Commit 7d998aa6f40015ebb53e01a61ca7c374cf6ddfd3
Exists in
master
and in
2 other branches
Merge branch 'master' of http://git.shunzhi.net/taohd/mycloud
# Conflicts: # cloud/haikang/src/main/java/com/sincere/haikang/CMSServer.java
Showing
200 changed files
with
8000 additions
and
4380 deletions
Show diff stats
Too many changes.
To preserve performance only 100 of 200 files displayed.
cloud/Capture/2019-08-06/2019-08-06_08-34-58.jpg
14.7 KB
cloud/Capture/2019-08-06/2019-08-06_08-35-26.jpg
14.1 KB
cloud/GateSnapPicture/1565064083617GateSnapPicture.jpg
13.7 KB
cloud/GateSnapPicture/1565064085046GateSnapPicture.jpg
13.6 KB
cloud/GateSnapPicture/1565064086448GateSnapPicture.jpg
14.3 KB
cloud/HCAapSDKCom/zlib1.dll
No preview for this file type
cloud/ailive/.gitignore
| ... | ... | @@ -1,31 +0,0 @@ |
| 1 | -HELP.md | |
| 2 | -target/ | |
| 3 | -!.mvn/wrapper/maven-wrapper.jar | |
| 4 | -!**/src/main/** | |
| 5 | -!**/src/test/** | |
| 6 | - | |
| 7 | -### STS ### | |
| 8 | -.apt_generated | |
| 9 | -.classpath | |
| 10 | -.factorypath | |
| 11 | -.project | |
| 12 | -.settings | |
| 13 | -.springBeans | |
| 14 | -.sts4-cache | |
| 15 | - | |
| 16 | -### IntelliJ IDEA ### | |
| 17 | -.idea | |
| 18 | -*.iws | |
| 19 | -*.iml | |
| 20 | -*.ipr | |
| 21 | - | |
| 22 | -### NetBeans ### | |
| 23 | -/nbproject/private/ | |
| 24 | -/nbbuild/ | |
| 25 | -/dist/ | |
| 26 | -/nbdist/ | |
| 27 | -/.nb-gradle/ | |
| 28 | -build/ | |
| 29 | - | |
| 30 | -### VS Code ### | |
| 31 | -.vscode/ |
cloud/ailive/.mvn/wrapper/MavenWrapperDownloader.java
| ... | ... | @@ -1,114 +0,0 @@ |
| 1 | -/* | |
| 2 | -Licensed to the Apache Software Foundation (ASF) under one | |
| 3 | -or more contributor license agreements. See the NOTICE file | |
| 4 | -distributed with this work for additional information | |
| 5 | -regarding copyright ownership. The ASF licenses this file | |
| 6 | -to you under the Apache License, Version 2.0 (the | |
| 7 | -"License"); you may not use this file except in compliance | |
| 8 | -with the License. You may obtain a copy of the License at | |
| 9 | - | |
| 10 | - https://www.apache.org/licenses/LICENSE-2.0 | |
| 11 | - | |
| 12 | -Unless required by applicable law or agreed to in writing, | |
| 13 | -software distributed under the License is distributed on an | |
| 14 | -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| 15 | -KIND, either express or implied. See the License for the | |
| 16 | -specific language governing permissions and limitations | |
| 17 | -under the License. | |
| 18 | -*/ | |
| 19 | - | |
| 20 | -import java.io.File; | |
| 21 | -import java.io.FileInputStream; | |
| 22 | -import java.io.FileOutputStream; | |
| 23 | -import java.io.IOException; | |
| 24 | -import java.net.URL; | |
| 25 | -import java.nio.channels.Channels; | |
| 26 | -import java.nio.channels.ReadableByteChannel; | |
| 27 | -import java.util.Properties; | |
| 28 | - | |
| 29 | -public class MavenWrapperDownloader { | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. | |
| 33 | - */ | |
| 34 | - private static final String DEFAULT_DOWNLOAD_URL = | |
| 35 | - "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; | |
| 36 | - | |
| 37 | - /** | |
| 38 | - * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to | |
| 39 | - * use instead of the default one. | |
| 40 | - */ | |
| 41 | - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = | |
| 42 | - ".mvn/wrapper/maven-wrapper.properties"; | |
| 43 | - | |
| 44 | - /** | |
| 45 | - * Path where the maven-wrapper.jar will be saved to. | |
| 46 | - */ | |
| 47 | - private static final String MAVEN_WRAPPER_JAR_PATH = | |
| 48 | - ".mvn/wrapper/maven-wrapper.jar"; | |
| 49 | - | |
| 50 | - /** | |
| 51 | - * Name of the property which should be used to override the default download url for the wrapper. | |
| 52 | - */ | |
| 53 | - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; | |
| 54 | - | |
| 55 | - public static void main(String args[]) { | |
| 56 | - System.out.println("- Downloader started"); | |
| 57 | - File baseDirectory = new File(args[0]); | |
| 58 | - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); | |
| 59 | - | |
| 60 | - // If the maven-wrapper.properties exists, read it and check if it contains a custom | |
| 61 | - // wrapperUrl parameter. | |
| 62 | - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); | |
| 63 | - String url = DEFAULT_DOWNLOAD_URL; | |
| 64 | - if (mavenWrapperPropertyFile.exists()) { | |
| 65 | - FileInputStream mavenWrapperPropertyFileInputStream = null; | |
| 66 | - try { | |
| 67 | - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); | |
| 68 | - Properties mavenWrapperProperties = new Properties(); | |
| 69 | - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); | |
| 70 | - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); | |
| 71 | - } catch (IOException e) { | |
| 72 | - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); | |
| 73 | - } finally { | |
| 74 | - try { | |
| 75 | - if (mavenWrapperPropertyFileInputStream != null) { | |
| 76 | - mavenWrapperPropertyFileInputStream.close(); | |
| 77 | - } | |
| 78 | - } catch (IOException e) { | |
| 79 | - // Ignore ... | |
| 80 | - } | |
| 81 | - } | |
| 82 | - } | |
| 83 | - System.out.println("- Downloading from: : " + url); | |
| 84 | - | |
| 85 | - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); | |
| 86 | - if (!outputFile.getParentFile().exists()) { | |
| 87 | - if (!outputFile.getParentFile().mkdirs()) { | |
| 88 | - System.out.println( | |
| 89 | - "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); | |
| 90 | - } | |
| 91 | - } | |
| 92 | - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); | |
| 93 | - try { | |
| 94 | - downloadFileFromURL(url, outputFile); | |
| 95 | - System.out.println("Done"); | |
| 96 | - System.exit(0); | |
| 97 | - } catch (Throwable e) { | |
| 98 | - System.out.println("- Error downloading"); | |
| 99 | - e.printStackTrace(); | |
| 100 | - System.exit(1); | |
| 101 | - } | |
| 102 | - } | |
| 103 | - | |
| 104 | - private static void downloadFileFromURL(String urlString, File destination) throws Exception { | |
| 105 | - URL website = new URL(urlString); | |
| 106 | - ReadableByteChannel rbc; | |
| 107 | - rbc = Channels.newChannel(website.openStream()); | |
| 108 | - FileOutputStream fos = new FileOutputStream(destination); | |
| 109 | - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); | |
| 110 | - fos.close(); | |
| 111 | - rbc.close(); | |
| 112 | - } | |
| 113 | - | |
| 114 | -} |
cloud/ailive/.mvn/wrapper/maven-wrapper.jar
No preview for this file type
cloud/ailive/.mvn/wrapper/maven-wrapper.properties
| ... | ... | @@ -1 +0,0 @@ |
| 1 | -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip |
cloud/ailive/mvnw
| ... | ... | @@ -1,286 +0,0 @@ |
| 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 | -# https://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 "$@" |
cloud/ailive/mvnw.cmd
| ... | ... | @@ -1,161 +0,0 @@ |
| 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 https://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% |
cloud/ailive/pom.xml
| ... | ... | @@ -1,53 +0,0 @@ |
| 1 | -<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| 3 | - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| 4 | - <modelVersion>4.0.0</modelVersion> | |
| 5 | - <parent> | |
| 6 | - <groupId>org.springframework.boot</groupId> | |
| 7 | - <artifactId>spring-boot-starter-parent</artifactId> | |
| 8 | - <version>2.1.6.RELEASE</version> | |
| 9 | - <relativePath/> <!-- lookup parent from repository --> | |
| 10 | - </parent> | |
| 11 | - <groupId>com.ali.live</groupId> | |
| 12 | - <artifactId>alilive</artifactId> | |
| 13 | - <version>0.0.1-SNAPSHOT</version> | |
| 14 | - <name>alilive</name> | |
| 15 | - <description>Demo project for Spring Boot</description> | |
| 16 | - | |
| 17 | - <properties> | |
| 18 | - <java.version>1.8</java.version> | |
| 19 | - </properties> | |
| 20 | - | |
| 21 | - <dependencies> | |
| 22 | - <dependency> | |
| 23 | - <groupId>org.springframework.boot</groupId> | |
| 24 | - <artifactId>spring-boot-starter-quartz</artifactId> | |
| 25 | - </dependency> | |
| 26 | - <dependency> | |
| 27 | - <groupId>org.springframework.boot</groupId> | |
| 28 | - <artifactId>spring-boot-starter-web</artifactId> | |
| 29 | - </dependency> | |
| 30 | - | |
| 31 | - <dependency> | |
| 32 | - <groupId>org.springframework.boot</groupId> | |
| 33 | - <artifactId>spring-boot-starter-test</artifactId> | |
| 34 | - <scope>test</scope> | |
| 35 | - </dependency> | |
| 36 | - | |
| 37 | - <dependency> | |
| 38 | - <groupId>com.aliyun</groupId> | |
| 39 | - <artifactId>aliyun-java-sdk-live</artifactId> | |
| 40 | - <version>3.7.5</version> | |
| 41 | - </dependency> | |
| 42 | - </dependencies> | |
| 43 | - | |
| 44 | - <build> | |
| 45 | - <plugins> | |
| 46 | - <plugin> | |
| 47 | - <groupId>org.springframework.boot</groupId> | |
| 48 | - <artifactId>spring-boot-maven-plugin</artifactId> | |
| 49 | - </plugin> | |
| 50 | - </plugins> | |
| 51 | - </build> | |
| 52 | - | |
| 53 | -</project> |
cloud/ailive/src/main/java/com/ali/live/alilive/AliliveApplication.java
| ... | ... | @@ -1,13 +0,0 @@ |
| 1 | -package com.ali.live.alilive; | |
| 2 | - | |
| 3 | -import org.springframework.boot.SpringApplication; | |
| 4 | -import org.springframework.boot.autoconfigure.SpringBootApplication; | |
| 5 | - | |
| 6 | -@SpringBootApplication | |
| 7 | -public class AliliveApplication { | |
| 8 | - | |
| 9 | - public static void main(String[] args) { | |
| 10 | - SpringApplication.run(AliliveApplication.class, args); | |
| 11 | - } | |
| 12 | - | |
| 13 | -} |
cloud/ailive/src/main/resources/application.properties
No preview for this file type
cloud/ailive/src/test/java/com/ali/live/alilive/AliliveApplicationTests.java
| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | -package com.ali.live.alilive; | |
| 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 AliliveApplicationTests { | |
| 11 | - | |
| 12 | - @Test | |
| 13 | - public void contextLoads() { | |
| 14 | - } | |
| 15 | - | |
| 16 | -} |
| ... | ... | @@ -0,0 +1,31 @@ |
| 1 | +HELP.md | |
| 2 | +target/ | |
| 3 | +!.mvn/wrapper/maven-wrapper.jar | |
| 4 | +!**/src/main/** | |
| 5 | +!**/src/test/** | |
| 6 | + | |
| 7 | +### STS ### | |
| 8 | +.apt_generated | |
| 9 | +.classpath | |
| 10 | +.factorypath | |
| 11 | +.project | |
| 12 | +.settings | |
| 13 | +.springBeans | |
| 14 | +.sts4-cache | |
| 15 | + | |
| 16 | +### IntelliJ IDEA ### | |
| 17 | +.idea | |
| 18 | +*.iws | |
| 19 | +*.iml | |
| 20 | +*.ipr | |
| 21 | + | |
| 22 | +### NetBeans ### | |
| 23 | +/nbproject/private/ | |
| 24 | +/nbbuild/ | |
| 25 | +/dist/ | |
| 26 | +/nbdist/ | |
| 27 | +/.nb-gradle/ | |
| 28 | +build/ | |
| 29 | + | |
| 30 | +### VS Code ### | |
| 31 | +.vscode/ | ... | ... |
| ... | ... | @@ -0,0 +1,114 @@ |
| 1 | +/* | |
| 2 | +Licensed to the Apache Software Foundation (ASF) under one | |
| 3 | +or more contributor license agreements. See the NOTICE file | |
| 4 | +distributed with this work for additional information | |
| 5 | +regarding copyright ownership. The ASF licenses this file | |
| 6 | +to you under the Apache License, Version 2.0 (the | |
| 7 | +"License"); you may not use this file except in compliance | |
| 8 | +with the License. You may obtain a copy of the License at | |
| 9 | + | |
| 10 | + https://www.apache.org/licenses/LICENSE-2.0 | |
| 11 | + | |
| 12 | +Unless required by applicable law or agreed to in writing, | |
| 13 | +software distributed under the License is distributed on an | |
| 14 | +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| 15 | +KIND, either express or implied. See the License for the | |
| 16 | +specific language governing permissions and limitations | |
| 17 | +under the License. | |
| 18 | +*/ | |
| 19 | + | |
| 20 | +import java.io.File; | |
| 21 | +import java.io.FileInputStream; | |
| 22 | +import java.io.FileOutputStream; | |
| 23 | +import java.io.IOException; | |
| 24 | +import java.net.URL; | |
| 25 | +import java.nio.channels.Channels; | |
| 26 | +import java.nio.channels.ReadableByteChannel; | |
| 27 | +import java.util.Properties; | |
| 28 | + | |
| 29 | +public class MavenWrapperDownloader { | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. | |
| 33 | + */ | |
| 34 | + private static final String DEFAULT_DOWNLOAD_URL = | |
| 35 | + "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; | |
| 36 | + | |
| 37 | + /** | |
| 38 | + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to | |
| 39 | + * use instead of the default one. | |
| 40 | + */ | |
| 41 | + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = | |
| 42 | + ".mvn/wrapper/maven-wrapper.properties"; | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * Path where the maven-wrapper.jar will be saved to. | |
| 46 | + */ | |
| 47 | + private static final String MAVEN_WRAPPER_JAR_PATH = | |
| 48 | + ".mvn/wrapper/maven-wrapper.jar"; | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * Name of the property which should be used to override the default download url for the wrapper. | |
| 52 | + */ | |
| 53 | + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; | |
| 54 | + | |
| 55 | + public static void main(String args[]) { | |
| 56 | + System.out.println("- Downloader started"); | |
| 57 | + File baseDirectory = new File(args[0]); | |
| 58 | + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); | |
| 59 | + | |
| 60 | + // If the maven-wrapper.properties exists, read it and check if it contains a custom | |
| 61 | + // wrapperUrl parameter. | |
| 62 | + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); | |
| 63 | + String url = DEFAULT_DOWNLOAD_URL; | |
| 64 | + if (mavenWrapperPropertyFile.exists()) { | |
| 65 | + FileInputStream mavenWrapperPropertyFileInputStream = null; | |
| 66 | + try { | |
| 67 | + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); | |
| 68 | + Properties mavenWrapperProperties = new Properties(); | |
| 69 | + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); | |
| 70 | + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); | |
| 71 | + } catch (IOException e) { | |
| 72 | + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); | |
| 73 | + } finally { | |
| 74 | + try { | |
| 75 | + if (mavenWrapperPropertyFileInputStream != null) { | |
| 76 | + mavenWrapperPropertyFileInputStream.close(); | |
| 77 | + } | |
| 78 | + } catch (IOException e) { | |
| 79 | + // Ignore ... | |
| 80 | + } | |
| 81 | + } | |
| 82 | + } | |
| 83 | + System.out.println("- Downloading from: : " + url); | |
| 84 | + | |
| 85 | + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); | |
| 86 | + if (!outputFile.getParentFile().exists()) { | |
| 87 | + if (!outputFile.getParentFile().mkdirs()) { | |
| 88 | + System.out.println( | |
| 89 | + "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); | |
| 90 | + } | |
| 91 | + } | |
| 92 | + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); | |
| 93 | + try { | |
| 94 | + downloadFileFromURL(url, outputFile); | |
| 95 | + System.out.println("Done"); | |
| 96 | + System.exit(0); | |
| 97 | + } catch (Throwable e) { | |
| 98 | + System.out.println("- Error downloading"); | |
| 99 | + e.printStackTrace(); | |
| 100 | + System.exit(1); | |
| 101 | + } | |
| 102 | + } | |
| 103 | + | |
| 104 | + private static void downloadFileFromURL(String urlString, File destination) throws Exception { | |
| 105 | + URL website = new URL(urlString); | |
| 106 | + ReadableByteChannel rbc; | |
| 107 | + rbc = Channels.newChannel(website.openStream()); | |
| 108 | + FileOutputStream fos = new FileOutputStream(destination); | |
| 109 | + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); | |
| 110 | + fos.close(); | |
| 111 | + rbc.close(); | |
| 112 | + } | |
| 113 | + | |
| 114 | +} | ... | ... |
No preview for this file type
| ... | ... | @@ -0,0 +1 @@ |
| 1 | +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip | ... | ... |
| ... | ... | @@ -0,0 +1,286 @@ |
| 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 | +# https://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 "$@" | ... | ... |
| ... | ... | @@ -0,0 +1,161 @@ |
| 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 https://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% | ... | ... |
| ... | ... | @@ -0,0 +1,106 @@ |
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| 3 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| 4 | + <modelVersion>4.0.0</modelVersion> | |
| 5 | + <parent> | |
| 6 | + <groupId>org.springframework.boot</groupId> | |
| 7 | + <artifactId>spring-boot-starter-parent</artifactId> | |
| 8 | + <version>2.1.7.RELEASE</version> | |
| 9 | + <relativePath/> <!-- lookup parent from repository --> | |
| 10 | + </parent> | |
| 11 | + <groupId>com.sincere</groupId> | |
| 12 | + <artifactId>autho</artifactId> | |
| 13 | + <version>0.0.1</version> | |
| 14 | + <name>autho</name> | |
| 15 | + <description>Demo project for Spring Boot</description> | |
| 16 | + | |
| 17 | + <properties> | |
| 18 | + <java.version>1.8</java.version> | |
| 19 | + <spring-cloud.version>Greenwich.SR2</spring-cloud.version> | |
| 20 | + </properties> | |
| 21 | + | |
| 22 | + <dependencies> | |
| 23 | + <dependency> | |
| 24 | + <groupId>com.sincere</groupId> | |
| 25 | + <artifactId>common</artifactId> | |
| 26 | + <version>0.0.1-SNAPSHOT</version> | |
| 27 | + </dependency> | |
| 28 | + <dependency> | |
| 29 | + <groupId>org.springframework.cloud</groupId> | |
| 30 | + <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> | |
| 31 | + </dependency> | |
| 32 | + <dependency> | |
| 33 | + <groupId>org.springframework.cloud</groupId> | |
| 34 | + <artifactId>spring-cloud-starter-oauth2</artifactId> | |
| 35 | + </dependency> | |
| 36 | + | |
| 37 | + <dependency> | |
| 38 | + <groupId>org.springframework.cloud</groupId> | |
| 39 | + <artifactId>spring-cloud-starter-security</artifactId> | |
| 40 | + <version>2.1.3.RELEASE</version> | |
| 41 | + </dependency> | |
| 42 | + | |
| 43 | + <dependency> | |
| 44 | + <groupId>org.springframework.boot</groupId> | |
| 45 | + <artifactId>spring-boot-starter-test</artifactId> | |
| 46 | + <scope>test</scope> | |
| 47 | + </dependency> | |
| 48 | + | |
| 49 | + <dependency> | |
| 50 | + <groupId>org.springframework.cloud</groupId> | |
| 51 | + <artifactId>spring-cloud-starter-openfeign</artifactId> | |
| 52 | + </dependency> | |
| 53 | + | |
| 54 | + <dependency> | |
| 55 | + <groupId>org.springframework.boot</groupId> | |
| 56 | + <artifactId>spring-boot-starter-data-redis</artifactId> | |
| 57 | + </dependency> | |
| 58 | + <dependency> | |
| 59 | + <groupId>com.alibaba</groupId> | |
| 60 | + <artifactId>fastjson</artifactId> | |
| 61 | + <version>1.2.58</version> | |
| 62 | + <scope>compile</scope> | |
| 63 | + </dependency> | |
| 64 | + | |
| 65 | + <dependency> | |
| 66 | + <groupId>io.grpc</groupId> | |
| 67 | + <artifactId>grpc-core</artifactId> | |
| 68 | + <version>1.18.0</version> | |
| 69 | + </dependency> | |
| 70 | + | |
| 71 | + <dependency> | |
| 72 | + <groupId>io.springfox</groupId> | |
| 73 | + <artifactId>springfox-swagger2</artifactId> | |
| 74 | + <version>2.9.2</version> | |
| 75 | + </dependency> | |
| 76 | + | |
| 77 | + <dependency> | |
| 78 | + <groupId>io.springfox</groupId> | |
| 79 | + <artifactId>springfox-swagger-ui</artifactId> | |
| 80 | + <version>2.9.2</version> | |
| 81 | + </dependency> | |
| 82 | + | |
| 83 | + </dependencies> | |
| 84 | + | |
| 85 | + <dependencyManagement> | |
| 86 | + <dependencies> | |
| 87 | + <dependency> | |
| 88 | + <groupId>org.springframework.cloud</groupId> | |
| 89 | + <artifactId>spring-cloud-dependencies</artifactId> | |
| 90 | + <version>${spring-cloud.version}</version> | |
| 91 | + <type>pom</type> | |
| 92 | + <scope>import</scope> | |
| 93 | + </dependency> | |
| 94 | + </dependencies> | |
| 95 | + </dependencyManagement> | |
| 96 | + | |
| 97 | + <build> | |
| 98 | + <plugins> | |
| 99 | + <plugin> | |
| 100 | + <groupId>org.springframework.boot</groupId> | |
| 101 | + <artifactId>spring-boot-maven-plugin</artifactId> | |
| 102 | + </plugin> | |
| 103 | + </plugins> | |
| 104 | + </build> | |
| 105 | + | |
| 106 | +</project> | ... | ... |
cloud/autho/src/main/java/com/sincere/autho/AuthoApplication.java
0 → 100644
| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | +package com.sincere.autho; | |
| 2 | + | |
| 3 | +import org.springframework.boot.SpringApplication; | |
| 4 | +import org.springframework.boot.autoconfigure.SpringBootApplication; | |
| 5 | +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | |
| 6 | + | |
| 7 | +@EnableDiscoveryClient | |
| 8 | +@SpringBootApplication | |
| 9 | +public class AuthoApplication { | |
| 10 | + | |
| 11 | + public static void main(String[] args) { | |
| 12 | + SpringApplication.run(AuthoApplication.class, args); | |
| 13 | + } | |
| 14 | + | |
| 15 | +} | ... | ... |
cloud/autho/src/main/java/com/sincere/autho/annotation/EnableLogging.java
0 → 100644
| ... | ... | @@ -0,0 +1,22 @@ |
| 1 | +package com.sincere.autho.annotation; | |
| 2 | + | |
| 3 | +import com.sincere.autho.autoconfigure.LoggingConfigurationSelector; | |
| 4 | +import org.springframework.context.annotation.Import; | |
| 5 | + | |
| 6 | +import java.lang.annotation.*; | |
| 7 | + | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * 启动日志框架支持 | |
| 11 | + * @author owen | |
| 12 | + * @create 2017年7月2日 | |
| 13 | + */ | |
| 14 | + | |
| 15 | +@Target(ElementType.TYPE) | |
| 16 | +@Retention(RetentionPolicy.RUNTIME) | |
| 17 | +@Documented | |
| 18 | +//自动装配starter | |
| 19 | +@Import(LoggingConfigurationSelector.class) | |
| 20 | +public @interface EnableLogging{ | |
| 21 | +// String name() ; | |
| 22 | +} | |
| 0 | 23 | \ No newline at end of file | ... | ... |
cloud/autho/src/main/java/com/sincere/autho/annotation/datasource/DataSource.java
0 → 100644
| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | +package com.sincere.autho.annotation.datasource; | |
| 2 | + | |
| 3 | +import java.lang.annotation.*; | |
| 4 | + | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * 数据源选择 | |
| 8 | + * @author owen | |
| 9 | + * @create 2017年7月2日 | |
| 10 | + */ | |
| 11 | +@Target({ElementType.METHOD, ElementType.TYPE}) | |
| 12 | +@Retention(RetentionPolicy.RUNTIME) | |
| 13 | +@Documented | |
| 14 | +public @interface DataSource { | |
| 15 | + String name(); | |
| 16 | +} | |
| 0 | 17 | \ No newline at end of file | ... | ... |
cloud/autho/src/main/java/com/sincere/autho/annotation/log/LogAnnotation.java
0 → 100644
| ... | ... | @@ -0,0 +1,26 @@ |
| 1 | +package com.sincere.autho.annotation.log; | |
| 2 | + | |
| 3 | +import java.lang.annotation.*; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * 日志注解 | |
| 7 | + * @author owen | |
| 8 | + * @create 2017年7月2日 | |
| 9 | + */ | |
| 10 | +@Target({ElementType.METHOD, ElementType.TYPE}) | |
| 11 | +@Retention(RetentionPolicy.RUNTIME) | |
| 12 | +@Documented | |
| 13 | +public @interface LogAnnotation { | |
| 14 | + | |
| 15 | + /** | |
| 16 | + * 模块 | |
| 17 | + * @return | |
| 18 | + */ | |
| 19 | + String module(); | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * 记录执行参数 | |
| 23 | + * @return | |
| 24 | + */ | |
| 25 | + boolean recordRequestParam() default true; | |
| 26 | +} | ... | ... |
cloud/autho/src/main/java/com/sincere/autho/autoconfigure/LoggingConfigurationSelector.java
0 → 100644
| ... | ... | @@ -0,0 +1,23 @@ |
| 1 | +package com.sincere.autho.autoconfigure; | |
| 2 | + | |
| 3 | +import org.springframework.context.annotation.ImportSelector; | |
| 4 | +import org.springframework.core.type.AnnotationMetadata; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * @author owen | |
| 8 | + * @create 2017年7月2日 | |
| 9 | + * 装配bean | |
| 10 | + */ | |
| 11 | +public class LoggingConfigurationSelector implements ImportSelector { | |
| 12 | + | |
| 13 | + @Override | |
| 14 | + public String[] selectImports(AnnotationMetadata importingClassMetadata) { | |
| 15 | + // TODO Auto-generated method stub | |
| 16 | +// importingClassMetadata.getAllAnnotationAttributes(EnableEcho.class.getName()); | |
| 17 | + return new String[] { | |
| 18 | + "com.sincere.autho.autoconfigure.datasource.DataSourceAspect", | |
| 19 | + "com.sincere.autho.autoconfigure.log.LogAnnotationAspect" | |
| 20 | + }; | |
| 21 | + } | |
| 22 | + | |
| 23 | +} | ... | ... |
cloud/autho/src/main/java/com/sincere/autho/autoconfigure/datasource/DataSourceAspect.java
0 → 100644
| ... | ... | @@ -0,0 +1,42 @@ |
| 1 | +package com.sincere.autho.autoconfigure.datasource; | |
| 2 | + | |
| 3 | +import com.sincere.autho.annotation.datasource.DataSource; | |
| 4 | +import com.sincere.common.config.DataSourceHolder; | |
| 5 | +import com.sincere.common.config.DataSourceKey; | |
| 6 | +import org.aspectj.lang.JoinPoint; | |
| 7 | +import org.aspectj.lang.annotation.After; | |
| 8 | +import org.aspectj.lang.annotation.Aspect; | |
| 9 | +import org.aspectj.lang.annotation.Before; | |
| 10 | +import org.slf4j.Logger; | |
| 11 | +import org.slf4j.LoggerFactory; | |
| 12 | +import org.springframework.core.annotation.Order; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * 切换数据源Advice | |
| 16 | + */ | |
| 17 | +@Aspect | |
| 18 | +@Order(-1) // 保证该AOP在@Transactional之前执行 | |
| 19 | +public class DataSourceAspect { | |
| 20 | + | |
| 21 | + private static final Logger logger = LoggerFactory.getLogger(DataSourceAspect.class); | |
| 22 | + | |
| 23 | + @Before("@annotation(ds)") | |
| 24 | + public void changeDataSource(JoinPoint point, DataSource ds) throws Throwable { | |
| 25 | + String dsId = ds.name(); | |
| 26 | + try { | |
| 27 | + DataSourceKey dataSourceKey = DataSourceKey.valueOf(dsId); | |
| 28 | + DataSourceHolder.setDataSourceKey(dataSourceKey); | |
| 29 | + } catch (Exception e) { | |
| 30 | + logger.error("数据源[{}]不存在,使用默认数据源 > {}", ds.name(), point.getSignature()); | |
| 31 | + } | |
| 32 | + | |
| 33 | + | |
| 34 | + } | |
| 35 | + | |
| 36 | + @After("@annotation(ds)") | |
| 37 | + public void restoreDataSource(JoinPoint point, DataSource ds) { | |
| 38 | + logger.debug("Revert DataSource : {transIdo} > {}", ds.name(), point.getSignature()); | |
| 39 | + DataSourceHolder.clearDataSourceKey(); | |
| 40 | + } | |
| 41 | + | |
| 42 | +} | |
| 0 | 43 | \ No newline at end of file | ... | ... |
cloud/autho/src/main/java/com/sincere/autho/autoconfigure/log/LogAnnotationAspect.java
0 → 100644
| ... | ... | @@ -0,0 +1,133 @@ |
| 1 | +package com.sincere.autho.autoconfigure.log; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson.JSON; | |
| 4 | +import com.alibaba.fastjson.JSONObject; | |
| 5 | +import com.sincere.autho.annotation.log.LogAnnotation; | |
| 6 | +import com.sincere.autho.log.service.LogService; | |
| 7 | +import com.sincere.autho.log.service.impl.LogServiceImpl; | |
| 8 | +import com.sincere.autho.utils.SysUserUtil; | |
| 9 | +import com.sincere.common.model.log.SysLog; | |
| 10 | +import com.sincere.common.model.system.LoginAppUser; | |
| 11 | +import com.sincere.common.util.SpringUtils; | |
| 12 | +import org.aspectj.lang.ProceedingJoinPoint; | |
| 13 | +import org.aspectj.lang.annotation.Around; | |
| 14 | +import org.aspectj.lang.annotation.Aspect; | |
| 15 | +import org.aspectj.lang.reflect.MethodSignature; | |
| 16 | +import org.slf4j.Logger; | |
| 17 | +import org.slf4j.LoggerFactory; | |
| 18 | +import org.springframework.core.annotation.Order; | |
| 19 | + | |
| 20 | +import javax.servlet.http.HttpServletRequest; | |
| 21 | +import javax.servlet.http.HttpServletResponse; | |
| 22 | +import java.util.ArrayList; | |
| 23 | +import java.util.Date; | |
| 24 | +import java.util.List; | |
| 25 | +import java.util.concurrent.CompletableFuture; | |
| 26 | +import java.util.concurrent.ThreadLocalRandom; | |
| 27 | + | |
| 28 | +/** | |
| 29 | + * 保存日志 | |
| 30 | + * | |
| 31 | + * @author owen | |
| 32 | + * @create 2017年7月2日 | |
| 33 | + */ | |
| 34 | +@Aspect | |
| 35 | +@Order(-1) // 保证该AOP在@Transactional之前执行 | |
| 36 | +public class LogAnnotationAspect { | |
| 37 | + | |
| 38 | + private static final Logger logger = LoggerFactory.getLogger(LogAnnotationAspect.class); | |
| 39 | + | |
| 40 | + @Around("@annotation(ds)") | |
| 41 | + public Object logSave(ProceedingJoinPoint joinPoint, LogAnnotation ds) throws Throwable { | |
| 42 | + | |
| 43 | + // 请求流水号 | |
| 44 | + String transid = getRandom(); | |
| 45 | + // 记录开始时间 | |
| 46 | + long start = System.currentTimeMillis(); | |
| 47 | + // 获取方法参数 | |
| 48 | + String url = null; | |
| 49 | + String httpMethod = null; | |
| 50 | + Object result = null; | |
| 51 | + List<Object> httpReqArgs = new ArrayList<Object>(); | |
| 52 | + SysLog log = new SysLog(); | |
| 53 | + log.setCreateTime(new Date()); | |
| 54 | + LoginAppUser loginAppUser = SysUserUtil.getLoginAppUser(); | |
| 55 | + if (loginAppUser != null) { | |
| 56 | + log.setUsername(loginAppUser.getUsername()); | |
| 57 | + } | |
| 58 | + | |
| 59 | + MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); | |
| 60 | + | |
| 61 | + LogAnnotation logAnnotation = methodSignature.getMethod().getDeclaredAnnotation(LogAnnotation.class); | |
| 62 | + log.setModule(logAnnotation.module() + ":" + methodSignature.getDeclaringTypeName() + "/" | |
| 63 | + + methodSignature.getName()); | |
| 64 | + | |
| 65 | + Object[] args = joinPoint.getArgs();// 参数值 | |
| 66 | + url = methodSignature.getDeclaringTypeName() + "/"+ methodSignature.getName(); | |
| 67 | + for (Object object : args) { | |
| 68 | + if (object instanceof HttpServletRequest) { | |
| 69 | + HttpServletRequest request = (HttpServletRequest) object; | |
| 70 | + url = request.getRequestURI(); | |
| 71 | + httpMethod = request.getMethod(); | |
| 72 | + } else if (object instanceof HttpServletResponse) { | |
| 73 | + } else { | |
| 74 | + | |
| 75 | + httpReqArgs.add(object); | |
| 76 | + } | |
| 77 | + } | |
| 78 | + | |
| 79 | + try { | |
| 80 | + String params = JSONObject.toJSONString(httpReqArgs); | |
| 81 | + log.setParams(params); | |
| 82 | + // 打印请求参数参数 | |
| 83 | + logger.info("开始请求,transid={}, url={} , httpMethod={}, reqData={} ", transid, url, httpMethod, params); | |
| 84 | + } catch (Exception e) { | |
| 85 | + logger.error("记录参数失败:{}", e.getMessage()); | |
| 86 | + } | |
| 87 | + | |
| 88 | + try { | |
| 89 | + // 调用原来的方法 | |
| 90 | + result = joinPoint.proceed(); | |
| 91 | + log.setFlag(Boolean.TRUE); | |
| 92 | + } catch (Exception e) { | |
| 93 | + log.setFlag(Boolean.FALSE); | |
| 94 | + log.setRemark(e.getMessage()); | |
| 95 | + | |
| 96 | + throw e; | |
| 97 | + } finally { | |
| 98 | + | |
| 99 | + CompletableFuture.runAsync(() -> { | |
| 100 | + try { | |
| 101 | + if (logAnnotation.recordRequestParam()) { | |
| 102 | + LogService logService = SpringUtils.getBean(LogServiceImpl.class); | |
| 103 | + logService.save(log); | |
| 104 | + } | |
| 105 | + } catch (Exception e) { | |
| 106 | + logger.error("记录参数失败:{}", e.getMessage()); | |
| 107 | + } | |
| 108 | + | |
| 109 | + }); | |
| 110 | + // 获取回执报文及耗时 | |
| 111 | + logger.info("请求完成, transid={}, 耗时={}, resp={}:", transid, (System.currentTimeMillis() - start), | |
| 112 | + result == null ? null : JSON.toJSONString(result)); | |
| 113 | + | |
| 114 | + } | |
| 115 | + return result; | |
| 116 | + } | |
| 117 | + | |
| 118 | + /** | |
| 119 | + * 生成日志随机数 | |
| 120 | + * | |
| 121 | + * @return | |
| 122 | + */ | |
| 123 | + public String getRandom() { | |
| 124 | + int i = 0; | |
| 125 | + StringBuilder st = new StringBuilder(); | |
| 126 | + while (i < 5) { | |
| 127 | + i++; | |
| 128 | + st.append(ThreadLocalRandom.current().nextInt(10)); | |
| 129 | + } | |
| 130 | + return st.toString() + System.currentTimeMillis(); | |
| 131 | + } | |
| 132 | + | |
| 133 | +} | |
| 0 | 134 | \ No newline at end of file | ... | ... |
cloud/autho/src/main/java/com/sincere/autho/config/OAuth2ServerConfig.java
0 → 100644
| ... | ... | @@ -0,0 +1,260 @@ |
| 1 | + | |
| 2 | +package com.sincere.autho.config; | |
| 3 | + | |
| 4 | +import com.sincere.autho.service.RedisAuthorizationCodeServices; | |
| 5 | +import com.sincere.autho.service.RedisClientDetailsService; | |
| 6 | +import com.sincere.autho.token.RedisTemplateTokenStore; | |
| 7 | +import com.sincere.common.props.PermitUrlProperties; | |
| 8 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 9 | +import org.springframework.boot.autoconfigure.AutoConfigureAfter; | |
| 10 | +import org.springframework.boot.context.properties.EnableConfigurationProperties; | |
| 11 | +import org.springframework.context.annotation.Bean; | |
| 12 | +import org.springframework.context.annotation.Configuration; | |
| 13 | +import org.springframework.data.redis.core.RedisTemplate; | |
| 14 | +import org.springframework.security.authentication.AuthenticationManager; | |
| 15 | +import org.springframework.security.config.annotation.web.builders.HttpSecurity; | |
| 16 | +import org.springframework.security.config.annotation.web.builders.WebSecurity; | |
| 17 | +import org.springframework.security.core.userdetails.UserDetailsService; | |
| 18 | +import org.springframework.security.oauth2.common.OAuth2AccessToken; | |
| 19 | +import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; | |
| 20 | +import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; | |
| 21 | +import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; | |
| 22 | +import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; | |
| 23 | +import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; | |
| 24 | +import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; | |
| 25 | +import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; | |
| 26 | +import org.springframework.security.oauth2.provider.code.RandomValueAuthorizationCodeServices; | |
| 27 | +import org.springframework.security.oauth2.provider.error.WebResponseExceptionTranslator; | |
| 28 | +import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; | |
| 29 | +import org.springframework.security.oauth2.provider.token.store.JwtTokenStore; | |
| 30 | +import org.springframework.security.web.util.matcher.RequestMatcher; | |
| 31 | +import org.springframework.stereotype.Component; | |
| 32 | +import org.springframework.util.AntPathMatcher; | |
| 33 | + | |
| 34 | +import javax.annotation.Resource; | |
| 35 | +import javax.servlet.http.HttpServletRequest; | |
| 36 | +import javax.sql.DataSource; | |
| 37 | + | |
| 38 | +/** | |
| 39 | + * @author owen 624191343@qq.com | |
| 40 | + * @version 创建时间:2017年11月12日 上午22:57:51 | |
| 41 | + */ | |
| 42 | +@Configuration | |
| 43 | +public class OAuth2ServerConfig { | |
| 44 | + | |
| 45 | + @Resource | |
| 46 | + private DataSource dataSource; | |
| 47 | + @Resource | |
| 48 | + private RedisTemplate<String, Object> redisTemplate; | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * 声明 ClientDetails实现 | |
| 52 | + */ | |
| 53 | + @Bean | |
| 54 | + public RedisClientDetailsService redisClientDetailsService() { | |
| 55 | + RedisClientDetailsService clientDetailsService = new RedisClientDetailsService(dataSource); | |
| 56 | + clientDetailsService.setRedisTemplate(redisTemplate); | |
| 57 | + return clientDetailsService; | |
| 58 | + } | |
| 59 | + | |
| 60 | + | |
| 61 | + @Bean | |
| 62 | + public RandomValueAuthorizationCodeServices authorizationCodeServices() { | |
| 63 | + RedisAuthorizationCodeServices redisAuthorizationCodeServices = new RedisAuthorizationCodeServices(); | |
| 64 | + redisAuthorizationCodeServices.setRedisTemplate(redisTemplate); | |
| 65 | + return redisAuthorizationCodeServices; | |
| 66 | + } | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * @author owen 624191343@qq.com | |
| 70 | + * @version 创建时间:2017年11月12日 上午22:57:51 默认token存储在内存中 | |
| 71 | + * DefaultTokenServices默认处理 | |
| 72 | + */ | |
| 73 | + @Component | |
| 74 | + @Configuration | |
| 75 | + @EnableAuthorizationServer | |
| 76 | + @AutoConfigureAfter(AuthorizationServerEndpointsConfigurer.class) | |
| 77 | + public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter { | |
| 78 | + /** | |
| 79 | + * 注入authenticationManager 来支持 password grant type | |
| 80 | + */ | |
| 81 | + @Autowired | |
| 82 | + private AuthenticationManager authenticationManager; | |
| 83 | + | |
| 84 | + @Autowired | |
| 85 | + private UserDetailsService userDetailsService; | |
| 86 | + | |
| 87 | + @Autowired(required = false) | |
| 88 | + private RedisTemplateTokenStore redisTokenStore; | |
| 89 | + | |
| 90 | + @Autowired(required = false) | |
| 91 | + private JwtTokenStore jwtTokenStore; | |
| 92 | + @Autowired(required = false) | |
| 93 | + private JwtAccessTokenConverter jwtAccessTokenConverter; | |
| 94 | + | |
| 95 | + @Autowired | |
| 96 | + private WebResponseExceptionTranslator webResponseExceptionTranslator; | |
| 97 | + | |
| 98 | + @Autowired | |
| 99 | + private RedisClientDetailsService redisClientDetailsService; | |
| 100 | + | |
| 101 | + @Autowired(required = false) | |
| 102 | + private RandomValueAuthorizationCodeServices authorizationCodeServices; | |
| 103 | + | |
| 104 | + /** | |
| 105 | + * 配置身份认证器,配置认证方式,TokenStore,TokenGranter,OAuth2RequestFactory | |
| 106 | + */ | |
| 107 | + public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { | |
| 108 | + | |
| 109 | + if (jwtTokenStore != null) { | |
| 110 | + endpoints.tokenStore(jwtTokenStore).authenticationManager(authenticationManager) | |
| 111 | + // 支持 | |
| 112 | + .userDetailsService(userDetailsService); | |
| 113 | + // password | |
| 114 | + // grant | |
| 115 | + // type; | |
| 116 | + } else if (redisTokenStore != null) { | |
| 117 | + endpoints.tokenStore(redisTokenStore).authenticationManager(authenticationManager) | |
| 118 | + // 支持 | |
| 119 | + .userDetailsService(userDetailsService); | |
| 120 | + // password | |
| 121 | + // grant | |
| 122 | + // type; | |
| 123 | + } | |
| 124 | + | |
| 125 | + if (jwtAccessTokenConverter != null) { | |
| 126 | + endpoints.accessTokenConverter(jwtAccessTokenConverter); | |
| 127 | + } | |
| 128 | + | |
| 129 | + endpoints.authorizationCodeServices(authorizationCodeServices); | |
| 130 | + | |
| 131 | + endpoints.exceptionTranslator(webResponseExceptionTranslator); | |
| 132 | + | |
| 133 | + } | |
| 134 | + | |
| 135 | + /** | |
| 136 | + * 配置应用名称 应用id | |
| 137 | + * 配置OAuth2的客户端相关信息 | |
| 138 | + */ | |
| 139 | + @Override | |
| 140 | + public void configure(ClientDetailsServiceConfigurer clients) throws Exception { | |
| 141 | + | |
| 142 | + // if(clientDetailsService!=null){ | |
| 143 | + // clients.withClientDetails(clientDetailsService); | |
| 144 | + // }else{ | |
| 145 | + // clients.inMemory().withClient("neusoft1").secret("neusoft1") | |
| 146 | + // .authorizedGrantTypes("authorization_code", "password", | |
| 147 | + // "refresh_token").scopes("all") | |
| 148 | + // .resourceIds(SERVER_RESOURCE_ID).accessTokenValiditySeconds(1200) | |
| 149 | + // .refreshTokenValiditySeconds(50000) | |
| 150 | + // .and().withClient("neusoft2").secret("neusoft2") | |
| 151 | + // .authorizedGrantTypes("authorization_code", "password", | |
| 152 | + // "refresh_token").scopes("all") | |
| 153 | + // .resourceIds(SERVER_RESOURCE_ID).accessTokenValiditySeconds(1200) | |
| 154 | + // .refreshTokenValiditySeconds(50000) | |
| 155 | + // ; | |
| 156 | + // } | |
| 157 | + clients.withClientDetails(redisClientDetailsService); | |
| 158 | + redisClientDetailsService.loadAllClientToCache(); | |
| 159 | + } | |
| 160 | + | |
| 161 | + /** | |
| 162 | + * 对应于配置AuthorizationServer安全认证的相关信息,创建ClientCredentialsTokenEndpointFilter核心过滤器 | |
| 163 | + */ | |
| 164 | + @Override | |
| 165 | + public void configure(AuthorizationServerSecurityConfigurer security) throws Exception { | |
| 166 | + // url:/oauth/token_key,exposes | |
| 167 | + security.tokenKeyAccess("permitAll()") | |
| 168 | + /// public key for token | |
| 169 | + /// verification if using | |
| 170 | + /// JWT tokens | |
| 171 | + // url:/oauth/check_token | |
| 172 | + .checkTokenAccess("isAuthenticated()") | |
| 173 | + // allow check token | |
| 174 | + .allowFormAuthenticationForClients(); | |
| 175 | + | |
| 176 | + // security.allowFormAuthenticationForClients(); | |
| 177 | + //// security.tokenKeyAccess("permitAll()"); | |
| 178 | + // security.tokenKeyAccess("isAuthenticated()"); | |
| 179 | + } | |
| 180 | + | |
| 181 | + } | |
| 182 | + | |
| 183 | + /** | |
| 184 | + * 资源服务 | |
| 185 | + */ | |
| 186 | + @Configuration | |
| 187 | + @EnableResourceServer | |
| 188 | + @EnableConfigurationProperties(PermitUrlProperties.class) | |
| 189 | + public class ResourceServerConfig extends ResourceServerConfigurerAdapter { | |
| 190 | + | |
| 191 | + @Autowired | |
| 192 | + private PermitUrlProperties permitUrlProperties; | |
| 193 | + | |
| 194 | + public void configure(WebSecurity web) throws Exception { | |
| 195 | + web.ignoring().antMatchers("/health"); | |
| 196 | + web.ignoring().antMatchers("/oauth/user/token"); | |
| 197 | + web.ignoring().antMatchers("/oauth/client/token"); | |
| 198 | + } | |
| 199 | + | |
| 200 | + @Override | |
| 201 | + public void configure(HttpSecurity http) throws Exception { | |
| 202 | + http.requestMatcher( | |
| 203 | + /** | |
| 204 | + * 判断来源请求是否包含oauth2授权信息 | |
| 205 | + */ | |
| 206 | + new RequestMatcher() { | |
| 207 | + private AntPathMatcher antPathMatcher = new AntPathMatcher(); | |
| 208 | + | |
| 209 | + @Override | |
| 210 | + public boolean matches(HttpServletRequest request) { | |
| 211 | + // 请求参数中包含access_token参数 | |
| 212 | + if (request.getParameter(OAuth2AccessToken.ACCESS_TOKEN) != null) { | |
| 213 | + return true; | |
| 214 | + } | |
| 215 | + | |
| 216 | + // 头部的Authorization值以Bearer开头 | |
| 217 | + String auth = request.getHeader("Authorization"); | |
| 218 | + if (auth != null) { | |
| 219 | + if (auth.startsWith(OAuth2AccessToken.BEARER_TYPE)) { | |
| 220 | + return true; | |
| 221 | + } | |
| 222 | + } | |
| 223 | + if (antPathMatcher.match(request.getRequestURI(), "/oauth/userinfo")) { | |
| 224 | + return true; | |
| 225 | + } | |
| 226 | + if (antPathMatcher.match(request.getRequestURI(), "/oauth/remove/token")) { | |
| 227 | + return true; | |
| 228 | + } | |
| 229 | + if (antPathMatcher.match(request.getRequestURI(), "/oauth/get/token")) { | |
| 230 | + return true; | |
| 231 | + } | |
| 232 | + if (antPathMatcher.match(request.getRequestURI(), "/oauth/refresh/token")) { | |
| 233 | + return true; | |
| 234 | + } | |
| 235 | + | |
| 236 | + if (antPathMatcher.match(request.getRequestURI(), "/oauth/token/list")) { | |
| 237 | + return true; | |
| 238 | + } | |
| 239 | + | |
| 240 | + if (antPathMatcher.match("/clients/**", request.getRequestURI())) { | |
| 241 | + return true; | |
| 242 | + } | |
| 243 | + | |
| 244 | + if (antPathMatcher.match("/services/**", request.getRequestURI())) { | |
| 245 | + return true; | |
| 246 | + } | |
| 247 | + if (antPathMatcher.match("/redis/**", request.getRequestURI())) { | |
| 248 | + return true; | |
| 249 | + } | |
| 250 | + return false; | |
| 251 | + } | |
| 252 | + } | |
| 253 | + | |
| 254 | + ).authorizeRequests().antMatchers(permitUrlProperties.getIgnored()).permitAll().anyRequest() | |
| 255 | + .authenticated(); | |
| 256 | + } | |
| 257 | + | |
| 258 | + } | |
| 259 | + | |
| 260 | +} | ... | ... |
cloud/autho/src/main/java/com/sincere/autho/config/SecurityConfig.java
0 → 100644
| ... | ... | @@ -0,0 +1,129 @@ |
| 1 | +package com.sincere.autho.config; | |
| 2 | + | |
| 3 | +import com.sincere.autho.handler.OauthLogoutHandler; | |
| 4 | +import com.sincere.common.props.PermitUrlProperties; | |
| 5 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 6 | +import org.springframework.boot.context.properties.EnableConfigurationProperties; | |
| 7 | +import org.springframework.context.annotation.Bean; | |
| 8 | +import org.springframework.context.annotation.Configuration; | |
| 9 | +import org.springframework.security.authentication.AuthenticationManager; | |
| 10 | +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; | |
| 11 | +import org.springframework.security.config.annotation.web.builders.HttpSecurity; | |
| 12 | +import org.springframework.security.config.annotation.web.builders.WebSecurity; | |
| 13 | +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | |
| 14 | +import org.springframework.security.config.http.SessionCreationPolicy; | |
| 15 | +import org.springframework.security.core.userdetails.UserDetailsService; | |
| 16 | +import org.springframework.security.crypto.password.PasswordEncoder; | |
| 17 | +import org.springframework.security.web.AuthenticationEntryPoint; | |
| 18 | +import org.springframework.security.web.authentication.AuthenticationFailureHandler; | |
| 19 | +import org.springframework.security.web.authentication.AuthenticationSuccessHandler; | |
| 20 | +import org.springframework.security.web.authentication.logout.HttpStatusReturningLogoutSuccessHandler; | |
| 21 | + | |
| 22 | +/** | |
| 23 | + * spring security配置 | |
| 24 | + * 在WebSecurityConfigurerAdapter不拦截oauth要开放的资源 | |
| 25 | + */ | |
| 26 | +@Configuration | |
| 27 | +//@EnableWebSecurity | |
| 28 | +//@EnableGlobalMethodSecurity(prePostEnabled = true) | |
| 29 | +@EnableConfigurationProperties(PermitUrlProperties.class) | |
| 30 | +public class SecurityConfig extends WebSecurityConfigurerAdapter { | |
| 31 | + | |
| 32 | + @Autowired | |
| 33 | + private AuthenticationSuccessHandler authenticationSuccessHandler; | |
| 34 | + @Autowired | |
| 35 | + private AuthenticationFailureHandler authenticationFailureHandler; | |
| 36 | + // @Autowired | |
| 37 | + // private LogoutSuccessHandler logoutSuccessHandler; | |
| 38 | + @Autowired(required = false) | |
| 39 | + private AuthenticationEntryPoint authenticationEntryPoint; | |
| 40 | + @Autowired | |
| 41 | + private UserDetailsService userDetailsService; | |
| 42 | + | |
| 43 | + @Autowired | |
| 44 | + private PasswordEncoder passwordEncoder; | |
| 45 | + | |
| 46 | + @Autowired | |
| 47 | + private OauthLogoutHandler oauthLogoutHandler; | |
| 48 | + @Autowired | |
| 49 | + private PermitUrlProperties permitUrlProperties ; | |
| 50 | + | |
| 51 | + @Autowired | |
| 52 | + private ValidateCodeSecurityConfig validateCodeSecurityConfig ; | |
| 53 | + | |
| 54 | + @Override | |
| 55 | + public void configure(WebSecurity web) throws Exception { | |
| 56 | + web.ignoring().antMatchers("/v2/api-docs", "/configuration/ui", "/swagger-resources", "/configuration/security", | |
| 57 | + "/swagger-ui.html", "/webjars/**", "/doc.html", "/login.html"); | |
| 58 | + web.ignoring().antMatchers("/js/**"); | |
| 59 | + web.ignoring().antMatchers("/css/**"); | |
| 60 | + web.ignoring().antMatchers("/health"); | |
| 61 | + // 忽略登录界面 | |
| 62 | + web.ignoring().antMatchers("/login.html"); | |
| 63 | + web.ignoring().antMatchers("/index.html"); | |
| 64 | + web.ignoring().antMatchers("/oauth/user/token"); | |
| 65 | + web.ignoring().antMatchers("/oauth/client/token"); | |
| 66 | + web.ignoring().antMatchers("/validata/code/**"); | |
| 67 | + web.ignoring().antMatchers(permitUrlProperties.getIgnored()); | |
| 68 | + | |
| 69 | + } | |
| 70 | + /** | |
| 71 | + * 认证管理 | |
| 72 | + * | |
| 73 | + * @return 认证管理对象 | |
| 74 | + * @throws Exception | |
| 75 | + * 认证异常信息 | |
| 76 | + */ | |
| 77 | + @Override | |
| 78 | + @Bean | |
| 79 | + public AuthenticationManager authenticationManagerBean() throws Exception { | |
| 80 | + return super.authenticationManagerBean(); | |
| 81 | + } | |
| 82 | + | |
| 83 | + @Override | |
| 84 | + protected void configure(HttpSecurity http) throws Exception { | |
| 85 | + http.csrf().disable(); | |
| 86 | + | |
| 87 | + http.authorizeRequests() | |
| 88 | + .anyRequest().authenticated(); | |
| 89 | + http.formLogin().loginPage("/login.html").loginProcessingUrl("/user/login") | |
| 90 | + .successHandler(authenticationSuccessHandler).failureHandler(authenticationFailureHandler); | |
| 91 | + | |
| 92 | + // 基于密码 等模式可以无session,不支持授权码模式 | |
| 93 | + if (authenticationEntryPoint != null) { | |
| 94 | + http.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint); | |
| 95 | + http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); | |
| 96 | + | |
| 97 | + } else { | |
| 98 | + // 授权码模式单独处理,需要session的支持,此模式可以支持所有oauth2的认证 | |
| 99 | + http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED); | |
| 100 | + } | |
| 101 | + | |
| 102 | + http.logout().logoutSuccessUrl("/login.html") | |
| 103 | + .logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler()) | |
| 104 | + .addLogoutHandler(oauthLogoutHandler).clearAuthentication(true); | |
| 105 | + | |
| 106 | + //增加验证码处理 | |
| 107 | + http.apply(validateCodeSecurityConfig) ; | |
| 108 | + // http.logout().logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler); | |
| 109 | + // 解决不允许显示在iframe的问题 | |
| 110 | + http.headers().frameOptions().disable(); | |
| 111 | + http.headers().cacheControl(); | |
| 112 | + | |
| 113 | + } | |
| 114 | + | |
| 115 | + /** | |
| 116 | + * 全局用户信息 | |
| 117 | + * | |
| 118 | + * @param auth | |
| 119 | + * 认证管理 | |
| 120 | + * @throws Exception | |
| 121 | + * 用户认证异常信息 | |
| 122 | + */ | |
| 123 | + @Autowired | |
| 124 | + public void globalUserDetails(AuthenticationManagerBuilder auth) throws Exception { | |
| 125 | + auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder); | |
| 126 | + } | |
| 127 | + | |
| 128 | + | |
| 129 | +} | ... | ... |
cloud/autho/src/main/java/com/sincere/autho/config/ValidateCodeSecurityConfig.java
0 → 100644
| ... | ... | @@ -0,0 +1,29 @@ |
| 1 | +/** | |
| 2 | + * | |
| 3 | + */ | |
| 4 | +package com.sincere.autho.config; | |
| 5 | + | |
| 6 | +import org.springframework.security.config.annotation.SecurityConfigurerAdapter; | |
| 7 | +import org.springframework.security.config.annotation.web.builders.HttpSecurity; | |
| 8 | +import org.springframework.security.web.DefaultSecurityFilterChain; | |
| 9 | +import org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter; | |
| 10 | +import org.springframework.stereotype.Component; | |
| 11 | + | |
| 12 | +import javax.annotation.Resource; | |
| 13 | +import javax.servlet.Filter; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * 校验码相关安全配置 | |
| 17 | + * | |
| 18 | + * @author zlt | |
| 19 | + */ | |
| 20 | +@Component("validateCodeSecurityConfig") | |
| 21 | +public class ValidateCodeSecurityConfig extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> { | |
| 22 | + @Resource | |
| 23 | + private Filter validateCodeFilter; | |
| 24 | + | |
| 25 | + @Override | |
| 26 | + public void configure(HttpSecurity http) { | |
| 27 | + http.addFilterBefore(validateCodeFilter, AbstractPreAuthenticatedProcessingFilter.class); | |
| 28 | + } | |
| 29 | +} | ... | ... |
cloud/autho/src/main/java/com/sincere/autho/control/OAuth2Controller.java
0 → 100644
| ... | ... | @@ -0,0 +1,482 @@ |
| 1 | +package com.sincere.autho.control; | |
| 2 | + | |
| 3 | +import com.fasterxml.jackson.core.JsonProcessingException; | |
| 4 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
| 5 | +import com.sincere.autho.annotation.log.LogAnnotation; | |
| 6 | +import com.sincere.autho.service.RedisClientDetailsService; | |
| 7 | +import com.sincere.autho.utils.SpringUtil; | |
| 8 | +import com.sincere.common.commons.PageResult; | |
| 9 | +import com.sincere.common.model.system.LoginAppUser; | |
| 10 | +import com.sincere.common.model.system.SysPermission; | |
| 11 | +import io.swagger.annotations.Api; | |
| 12 | +import io.swagger.annotations.ApiOperation; | |
| 13 | +import io.swagger.annotations.ApiParam; | |
| 14 | +import org.apache.commons.collections.MapUtils; | |
| 15 | +import org.slf4j.Logger; | |
| 16 | +import org.slf4j.LoggerFactory; | |
| 17 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 18 | +import org.springframework.dao.DataAccessException; | |
| 19 | +import org.springframework.data.redis.connection.RedisConnection; | |
| 20 | +import org.springframework.data.redis.core.Cursor; | |
| 21 | +import org.springframework.data.redis.core.RedisCallback; | |
| 22 | +import org.springframework.data.redis.core.RedisTemplate; | |
| 23 | +import org.springframework.data.redis.core.ScanOptions; | |
| 24 | +import org.springframework.http.HttpStatus; | |
| 25 | +import org.springframework.security.authentication.AuthenticationManager; | |
| 26 | +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | |
| 27 | +import org.springframework.security.core.Authentication; | |
| 28 | +import org.springframework.security.core.context.SecurityContextHolder; | |
| 29 | +import org.springframework.security.crypto.password.PasswordEncoder; | |
| 30 | +import org.springframework.security.oauth2.common.OAuth2AccessToken; | |
| 31 | +import org.springframework.security.oauth2.common.exceptions.UnapprovedClientAuthenticationException; | |
| 32 | +import org.springframework.security.oauth2.provider.*; | |
| 33 | +import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; | |
| 34 | +import org.springframework.security.oauth2.provider.client.ClientCredentialsTokenGranter; | |
| 35 | +import org.springframework.security.oauth2.provider.refresh.RefreshTokenGranter; | |
| 36 | +import org.springframework.security.oauth2.provider.request.DefaultOAuth2RequestFactory; | |
| 37 | +import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices; | |
| 38 | +import org.springframework.security.oauth2.provider.token.TokenStore; | |
| 39 | +import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; | |
| 40 | +import org.springframework.web.bind.annotation.PostMapping; | |
| 41 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 42 | +import org.springframework.web.bind.annotation.RequestParam; | |
| 43 | +import org.springframework.web.bind.annotation.RestController; | |
| 44 | + | |
| 45 | +import javax.annotation.Resource; | |
| 46 | +import javax.servlet.http.HttpServletRequest; | |
| 47 | +import javax.servlet.http.HttpServletResponse; | |
| 48 | +import java.io.IOException; | |
| 49 | +import java.util.*; | |
| 50 | + | |
| 51 | +/** | |
| 52 | + * @author 作者 owen E-mail: 624191343@qq.com | |
| 53 | + * @version 创建时间:2018年4月28日 下午2:18:54 类说明 | |
| 54 | + */ | |
| 55 | + | |
| 56 | +@Api(tags = "OAuth2相关操作") | |
| 57 | +@RestController | |
| 58 | +public class OAuth2Controller { | |
| 59 | + | |
| 60 | + private static final Logger logger = LoggerFactory.getLogger(OAuth2Controller.class); | |
| 61 | + @Resource | |
| 62 | + private ObjectMapper objectMapper; // springmvc启动时自动装配json处理类 | |
| 63 | + @Autowired | |
| 64 | + private PasswordEncoder passwordEncoder; | |
| 65 | + | |
| 66 | + @Autowired | |
| 67 | + private TokenStore tokenStore; | |
| 68 | + | |
| 69 | + @Autowired | |
| 70 | + private RedisTemplate<String, Object> redisTemplate; | |
| 71 | + | |
| 72 | + @ApiOperation(value = "用户名密码获取token") | |
| 73 | + @PostMapping("/oauth/user/token") | |
| 74 | + public void getUserTokenInfo( | |
| 75 | + @ApiParam(required = true, name = "username", value = "账号") @RequestParam(value = "username") String username, | |
| 76 | + @ApiParam(required = true, name = "password", value = "密码") @RequestParam(value = "password") String password, | |
| 77 | + HttpServletRequest request, HttpServletResponse response) { | |
| 78 | + String clientId = request.getHeader("client_id"); | |
| 79 | + String clientSecret = request.getHeader("client_secret"); | |
| 80 | + | |
| 81 | + try { | |
| 82 | + | |
| 83 | + if (clientId == null || "".equals(clientId)) { | |
| 84 | + throw new UnapprovedClientAuthenticationException("请求头中无client_id信息"); | |
| 85 | + } | |
| 86 | + | |
| 87 | + if (clientSecret == null || "".equals(clientSecret)) { | |
| 88 | + throw new UnapprovedClientAuthenticationException("请求头中无client_secret信息"); | |
| 89 | + } | |
| 90 | + | |
| 91 | + RedisClientDetailsService clientDetailsService = SpringUtil.getBean(RedisClientDetailsService.class); | |
| 92 | + | |
| 93 | + ClientDetails clientDetails = clientDetailsService.loadClientByClientId(clientId); | |
| 94 | + | |
| 95 | + if (clientDetails == null) { | |
| 96 | + throw new UnapprovedClientAuthenticationException("clientId对应的信息不存在"); | |
| 97 | + } else if (!passwordEncoder.matches(clientSecret, clientDetails.getClientSecret())) { | |
| 98 | + throw new UnapprovedClientAuthenticationException("clientSecret不匹配"); | |
| 99 | + } | |
| 100 | + | |
| 101 | + TokenRequest tokenRequest = new TokenRequest(MapUtils.EMPTY_MAP, clientId, clientDetails.getScope(), | |
| 102 | + "customer"); | |
| 103 | + | |
| 104 | + OAuth2Request oAuth2Request = tokenRequest.createOAuth2Request(clientDetails); | |
| 105 | + | |
| 106 | + UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password); | |
| 107 | + | |
| 108 | + AuthenticationManager authenticationManager = SpringUtil.getBean(AuthenticationManager.class); | |
| 109 | + | |
| 110 | + Authentication authentication = authenticationManager.authenticate(token); | |
| 111 | + SecurityContextHolder.getContext().setAuthentication(authentication); | |
| 112 | + | |
| 113 | + OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(oAuth2Request, authentication); | |
| 114 | + | |
| 115 | + AuthorizationServerTokenServices authorizationServerTokenServices = SpringUtil | |
| 116 | + .getBean("defaultAuthorizationServerTokenServices", AuthorizationServerTokenServices.class); | |
| 117 | + | |
| 118 | + OAuth2AccessToken oAuth2AccessToken = authorizationServerTokenServices | |
| 119 | + .createAccessToken(oAuth2Authentication); | |
| 120 | + | |
| 121 | + oAuth2Authentication.setAuthenticated(true); | |
| 122 | + | |
| 123 | + response.setContentType("application/json;charset=UTF-8"); | |
| 124 | + response.getWriter().write(objectMapper.writeValueAsString(oAuth2AccessToken)); | |
| 125 | + response.getWriter().flush(); | |
| 126 | + response.getWriter().close(); | |
| 127 | + | |
| 128 | + } catch (Exception e) { | |
| 129 | + | |
| 130 | + response.setStatus(HttpStatus.UNAUTHORIZED.value()); | |
| 131 | + | |
| 132 | + response.setContentType("application/json;charset=UTF-8"); | |
| 133 | + | |
| 134 | + Map<String, String> rsp = new HashMap<>(); | |
| 135 | + rsp.put("resp_code", HttpStatus.UNAUTHORIZED.value() + ""); | |
| 136 | + rsp.put("rsp_msg", e.getMessage()); | |
| 137 | + | |
| 138 | + try { | |
| 139 | + response.getWriter().write(objectMapper.writeValueAsString(rsp)); | |
| 140 | + response.getWriter().flush(); | |
| 141 | + response.getWriter().close(); | |
| 142 | + } catch (JsonProcessingException e1) { | |
| 143 | + // TODO Auto-generated catch block | |
| 144 | + e1.printStackTrace(); | |
| 145 | + } catch (IOException e1) { | |
| 146 | + // TODO Auto-generated catch block | |
| 147 | + e1.printStackTrace(); | |
| 148 | + } | |
| 149 | + | |
| 150 | + } | |
| 151 | + } | |
| 152 | + | |
| 153 | + | |
| 154 | + @ApiOperation(value = "clientId获取token") | |
| 155 | + @PostMapping("/oauth/client/token") | |
| 156 | + @LogAnnotation(module = "autho", recordRequestParam = false) | |
| 157 | + public void getClientTokenInfo(HttpServletRequest request, HttpServletResponse response) { | |
| 158 | + | |
| 159 | + String clientId = request.getHeader("client_id"); | |
| 160 | + String clientSecret = request.getHeader("client_secret"); | |
| 161 | + try { | |
| 162 | + | |
| 163 | + if (clientId == null || "".equals(clientId)) { | |
| 164 | + throw new UnapprovedClientAuthenticationException("请求参数中无clientId信息"); | |
| 165 | + } | |
| 166 | + | |
| 167 | + if (clientSecret == null || "".equals(clientSecret)) { | |
| 168 | + throw new UnapprovedClientAuthenticationException("请求参数中无clientSecret信息"); | |
| 169 | + } | |
| 170 | + | |
| 171 | + RedisClientDetailsService clientDetailsService = SpringUtil.getBean(RedisClientDetailsService.class); | |
| 172 | + | |
| 173 | + ClientDetails clientDetails = clientDetailsService.loadClientByClientId(clientId); | |
| 174 | + | |
| 175 | + if (clientDetails == null) { | |
| 176 | + throw new UnapprovedClientAuthenticationException("clientId对应的信息不存在"); | |
| 177 | + } else if (!passwordEncoder.matches(clientSecret, clientDetails.getClientSecret())) { | |
| 178 | + throw new UnapprovedClientAuthenticationException("clientSecret不匹配"); | |
| 179 | + } | |
| 180 | + | |
| 181 | + Map<String, String> map = new HashMap<>(); | |
| 182 | + map.put("client_secret", clientSecret); | |
| 183 | + map.put("client_id", clientId); | |
| 184 | + map.put("grant_type", "client_credentials"); | |
| 185 | + TokenRequest tokenRequest = new TokenRequest(map, clientId, clientDetails.getScope(), "client_credentials"); | |
| 186 | + | |
| 187 | + OAuth2Request oAuth2Request = tokenRequest.createOAuth2Request(clientDetails); | |
| 188 | + | |
| 189 | + AuthorizationServerTokenServices authorizationServerTokenServices = SpringUtil | |
| 190 | + .getBean("defaultAuthorizationServerTokenServices", AuthorizationServerTokenServices.class); | |
| 191 | + OAuth2RequestFactory requestFactory = new DefaultOAuth2RequestFactory(clientDetailsService); | |
| 192 | + ClientCredentialsTokenGranter clientCredentialsTokenGranter = new ClientCredentialsTokenGranter( | |
| 193 | + authorizationServerTokenServices, clientDetailsService, requestFactory); | |
| 194 | + | |
| 195 | + clientCredentialsTokenGranter.setAllowRefresh(true); | |
| 196 | + OAuth2AccessToken oAuth2AccessToken = clientCredentialsTokenGranter.grant("client_credentials", | |
| 197 | + tokenRequest); | |
| 198 | + | |
| 199 | + response.setContentType("application/json;charset=UTF-8"); | |
| 200 | + response.getWriter().write(objectMapper.writeValueAsString(oAuth2AccessToken)); | |
| 201 | + response.getWriter().flush(); | |
| 202 | + response.getWriter().close(); | |
| 203 | + | |
| 204 | + } catch (Exception e) { | |
| 205 | + | |
| 206 | + response.setStatus(HttpStatus.UNAUTHORIZED.value()); | |
| 207 | + response.setContentType("application/json;charset=UTF-8"); | |
| 208 | + Map<String, String> rsp = new HashMap<>(); | |
| 209 | + rsp.put("resp_code", HttpStatus.UNAUTHORIZED.value() + ""); | |
| 210 | + rsp.put("rsp_msg", e.getMessage()); | |
| 211 | + | |
| 212 | + try { | |
| 213 | + response.getWriter().write(objectMapper.writeValueAsString(rsp)); | |
| 214 | + response.getWriter().flush(); | |
| 215 | + response.getWriter().close(); | |
| 216 | + } catch (JsonProcessingException e1) { | |
| 217 | + // TODO Auto-generated catch block | |
| 218 | + e1.printStackTrace(); | |
| 219 | + } catch (IOException e1) { | |
| 220 | + // TODO Auto-generated catch block | |
| 221 | + e1.printStackTrace(); | |
| 222 | + } | |
| 223 | + | |
| 224 | + } | |
| 225 | + } | |
| 226 | + | |
| 227 | + @ApiOperation(value = "access_token刷新token") | |
| 228 | + @PostMapping(value = "/oauth/refresh/token", params = "access_token") | |
| 229 | + public void refreshTokenInfo(String access_token, HttpServletRequest request, HttpServletResponse response) { | |
| 230 | + | |
| 231 | + // 拿到当前用户信息 | |
| 232 | + try { | |
| 233 | + Authentication user = SecurityContextHolder.getContext().getAuthentication(); | |
| 234 | + | |
| 235 | + if (user != null) { | |
| 236 | + if (user instanceof OAuth2Authentication) { | |
| 237 | + Authentication athentication = (Authentication) user; | |
| 238 | + OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) athentication.getDetails(); | |
| 239 | + } | |
| 240 | + | |
| 241 | + } | |
| 242 | + OAuth2AccessToken accessToken = tokenStore.readAccessToken(access_token); | |
| 243 | + OAuth2Authentication auth = (OAuth2Authentication) user; | |
| 244 | + RedisClientDetailsService clientDetailsService = SpringUtil.getBean(RedisClientDetailsService.class); | |
| 245 | + | |
| 246 | + ClientDetails clientDetails = clientDetailsService | |
| 247 | + .loadClientByClientId(auth.getOAuth2Request().getClientId()); | |
| 248 | + | |
| 249 | + AuthorizationServerTokenServices authorizationServerTokenServices = SpringUtil | |
| 250 | + .getBean("defaultAuthorizationServerTokenServices", AuthorizationServerTokenServices.class); | |
| 251 | + OAuth2RequestFactory requestFactory = new DefaultOAuth2RequestFactory(clientDetailsService); | |
| 252 | + | |
| 253 | + RefreshTokenGranter refreshTokenGranter = new RefreshTokenGranter(authorizationServerTokenServices, | |
| 254 | + clientDetailsService, requestFactory); | |
| 255 | + | |
| 256 | + Map<String, String> map = new HashMap<>(); | |
| 257 | + map.put("grant_type", "refresh_token"); | |
| 258 | + map.put("refresh_token", accessToken.getRefreshToken().getValue()); | |
| 259 | + TokenRequest tokenRequest = new TokenRequest(map, auth.getOAuth2Request().getClientId(), | |
| 260 | + auth.getOAuth2Request().getScope(), "refresh_token"); | |
| 261 | + | |
| 262 | + OAuth2AccessToken oAuth2AccessToken = refreshTokenGranter.grant("refresh_token", tokenRequest); | |
| 263 | + | |
| 264 | + tokenStore.removeAccessToken(accessToken); | |
| 265 | + | |
| 266 | + response.setContentType("application/json;charset=UTF-8"); | |
| 267 | + response.getWriter().write(objectMapper.writeValueAsString(oAuth2AccessToken)); | |
| 268 | + response.getWriter().flush(); | |
| 269 | + response.getWriter().close(); | |
| 270 | + } catch (Exception e) { | |
| 271 | + response.setStatus(HttpStatus.UNAUTHORIZED.value()); | |
| 272 | + response.setContentType("application/json;charset=UTF-8"); | |
| 273 | + Map<String, String> rsp = new HashMap<>(); | |
| 274 | + rsp.put("resp_code", HttpStatus.UNAUTHORIZED.value() + ""); | |
| 275 | + rsp.put("rsp_msg", e.getMessage()); | |
| 276 | + | |
| 277 | + try { | |
| 278 | + response.getWriter().write(objectMapper.writeValueAsString(rsp)); | |
| 279 | + response.getWriter().flush(); | |
| 280 | + response.getWriter().close(); | |
| 281 | + } catch (JsonProcessingException e1) { | |
| 282 | + // TODO Auto-generated catch block | |
| 283 | + e1.printStackTrace(); | |
| 284 | + } catch (IOException e1) { | |
| 285 | + // TODO Auto-generated catch block | |
| 286 | + e1.printStackTrace(); | |
| 287 | + } | |
| 288 | + } | |
| 289 | + | |
| 290 | + } | |
| 291 | + | |
| 292 | + /** | |
| 293 | + * 移除access_token和refresh_token | |
| 294 | + * | |
| 295 | + * @param access_token | |
| 296 | + */ | |
| 297 | + @ApiOperation(value = "移除token") | |
| 298 | + @PostMapping(value = "/oauth/remove/token", params = "access_token") | |
| 299 | + public void removeToken(String access_token) { | |
| 300 | + | |
| 301 | + // 拿到当前用户信息 | |
| 302 | + Authentication user = SecurityContextHolder.getContext().getAuthentication(); | |
| 303 | + | |
| 304 | + if (user != null) { | |
| 305 | + if (user instanceof OAuth2Authentication) { | |
| 306 | + Authentication athentication = (Authentication) user; | |
| 307 | + OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) athentication.getDetails(); | |
| 308 | + } | |
| 309 | + | |
| 310 | + } | |
| 311 | + OAuth2AccessToken accessToken = tokenStore.readAccessToken(access_token); | |
| 312 | + if (accessToken != null) { | |
| 313 | + // 移除access_token | |
| 314 | + tokenStore.removeAccessToken(accessToken); | |
| 315 | + | |
| 316 | + // 移除refresh_token | |
| 317 | + if (accessToken.getRefreshToken() != null) { | |
| 318 | + tokenStore.removeRefreshToken(accessToken.getRefreshToken()); | |
| 319 | + } | |
| 320 | + | |
| 321 | + } | |
| 322 | + } | |
| 323 | + | |
| 324 | + @ApiOperation(value = "获取token信息") | |
| 325 | + @PostMapping(value = "/oauth/get/token", params = "access_token") | |
| 326 | + public OAuth2AccessToken getTokenInfo(String access_token) { | |
| 327 | + | |
| 328 | + // 拿到当前用户信息 | |
| 329 | + Authentication user = SecurityContextHolder.getContext().getAuthentication(); | |
| 330 | + | |
| 331 | + if (user != null) { | |
| 332 | + if (user instanceof OAuth2Authentication) { | |
| 333 | + Authentication athentication = (Authentication) user; | |
| 334 | + OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) athentication.getDetails(); | |
| 335 | + } | |
| 336 | + | |
| 337 | + } | |
| 338 | + OAuth2AccessToken accessToken = tokenStore.readAccessToken(access_token); | |
| 339 | + | |
| 340 | + return accessToken; | |
| 341 | + | |
| 342 | + } | |
| 343 | + | |
| 344 | + /** | |
| 345 | + * 当前登陆用户信息 | |
| 346 | + * security获取当前登录用户的方法是SecurityContextHolder.getContext().getAuthentication() | |
| 347 | + * 这里的实现类是org.springframework.security.oauth2.provider.OAuth2Authentication | |
| 348 | + * | |
| 349 | + * @return | |
| 350 | + */ | |
| 351 | + @ApiOperation(value = "当前登陆用户信息") | |
| 352 | + @RequestMapping(value = { "/oauth/userinfo" }, produces = "application/json") // 获取用户信息。/auth/user | |
| 353 | + public Map<String, Object> getCurrentUserDetail() { | |
| 354 | + Map<String, Object> userInfo = new HashMap<>(); | |
| 355 | + userInfo.put("user", SecurityContextHolder.getContext().getAuthentication().getPrincipal()); | |
| 356 | + logger.debug("认证详细信息:" + SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString()); | |
| 357 | + | |
| 358 | + List<SysPermission> permissions = new ArrayList<>(); | |
| 359 | + | |
| 360 | + new ArrayList(SecurityContextHolder.getContext().getAuthentication().getAuthorities()).forEach(o -> { | |
| 361 | + SysPermission sysPermission = new SysPermission(); | |
| 362 | + sysPermission.setPermission(o.toString()); | |
| 363 | + permissions.add(sysPermission); | |
| 364 | + }); | |
| 365 | + // userInfo.put("authorities", | |
| 366 | + // AuthorityUtils.authorityListToSet(SecurityContextHolder.getContext().getAuthentication().getAuthorities()) | |
| 367 | + // ); | |
| 368 | + userInfo.put("permissions", permissions); | |
| 369 | + | |
| 370 | + userInfo.put("resp_code", "200"); | |
| 371 | + | |
| 372 | + logger.info("返回信息:{}", userInfo); | |
| 373 | + | |
| 374 | + return userInfo; | |
| 375 | + } | |
| 376 | + | |
| 377 | + @ApiOperation(value = "token列表") | |
| 378 | + @PostMapping("/oauth/token/list") | |
| 379 | + public PageResult<HashMap<String, String>> getUserTokenInfo(@RequestParam Map<String, Object> params) | |
| 380 | + throws Exception { | |
| 381 | + List<HashMap<String, String>> list = new ArrayList<>(); | |
| 382 | + | |
| 383 | + Set<String> keys = redisTemplate.keys("access:" + "*") ; | |
| 384 | +// Object key1 = keys.toArray()[0]; | |
| 385 | +// Object token1 = redisTemplate.opsForValue().get(key1); | |
| 386 | + //根据分页参数获取对应数据 | |
| 387 | + // List<String> pages = findKeysForPage("access:" + "*", MapUtils.getInteger(params, "page"),MapUtils.getInteger(params, "limit")); | |
| 388 | + | |
| 389 | + for (Object key: keys.toArray()) { | |
| 390 | +// String key = page; | |
| 391 | +// String accessToken = StringUtils.substringAfter(key, "access:"); | |
| 392 | +// OAuth2AccessToken token = tokenStore.readAccessToken(accessToken); | |
| 393 | + OAuth2AccessToken token = (OAuth2AccessToken)redisTemplate.opsForValue().get(key); | |
| 394 | + HashMap<String, String> map = new HashMap<String, String>(); | |
| 395 | + | |
| 396 | + try { | |
| 397 | + map.put("token_type", token.getTokenType()); | |
| 398 | + map.put("token_value", token.getValue()); | |
| 399 | + map.put("expires_in", token.getExpiresIn()+""); | |
| 400 | + } catch (Exception e) { | |
| 401 | + | |
| 402 | + } | |
| 403 | + | |
| 404 | + | |
| 405 | + OAuth2Authentication oAuth2Auth = tokenStore.readAuthentication(token); | |
| 406 | + Authentication authentication = oAuth2Auth.getUserAuthentication(); | |
| 407 | + | |
| 408 | + map.put("client_id", oAuth2Auth.getOAuth2Request().getClientId()); | |
| 409 | + map.put("grant_type", oAuth2Auth.getOAuth2Request().getGrantType()); | |
| 410 | + | |
| 411 | + if (authentication instanceof UsernamePasswordAuthenticationToken) { | |
| 412 | + UsernamePasswordAuthenticationToken authenticationToken = (UsernamePasswordAuthenticationToken) authentication; | |
| 413 | + | |
| 414 | + if(authenticationToken.getPrincipal() instanceof LoginAppUser ){ | |
| 415 | + LoginAppUser user = (LoginAppUser) authenticationToken.getPrincipal(); | |
| 416 | + map.put("user_id", user.getId()+""); | |
| 417 | + map.put("user_name", user.getUsername()+""); | |
| 418 | + map.put("user_head_imgurl", user.getHeadImgUrl()+""); | |
| 419 | + } | |
| 420 | + | |
| 421 | + | |
| 422 | + }else if (authentication instanceof PreAuthenticatedAuthenticationToken){ | |
| 423 | + //刷新token方式 | |
| 424 | + PreAuthenticatedAuthenticationToken authenticationToken = (PreAuthenticatedAuthenticationToken) authentication; | |
| 425 | + if(authenticationToken.getPrincipal() instanceof LoginAppUser ){ | |
| 426 | + LoginAppUser user = (LoginAppUser) authenticationToken.getPrincipal(); | |
| 427 | + map.put("user_id", user.getId()+""); | |
| 428 | + map.put("user_name", user.getUsername()+""); | |
| 429 | + map.put("user_head_imgurl", user.getHeadImgUrl()+""); | |
| 430 | + } | |
| 431 | + | |
| 432 | + } | |
| 433 | + list.add(map); | |
| 434 | + | |
| 435 | + } | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + return PageResult.<HashMap<String, String>>builder().data(list).code(0).count((long) keys.size()).build(); | |
| 440 | + | |
| 441 | + } | |
| 442 | + | |
| 443 | + public List<String> findKeysForPage(String patternKey, int pageNum, int pageSize) { | |
| 444 | + | |
| 445 | + Set<String> execute = redisTemplate.execute(new RedisCallback<Set<String>>() { | |
| 446 | + | |
| 447 | + @Override | |
| 448 | + public Set<String> doInRedis(RedisConnection connection) throws DataAccessException { | |
| 449 | + | |
| 450 | + Set<String> binaryKeys = new HashSet<>(); | |
| 451 | + | |
| 452 | + Cursor<byte[]> cursor = connection | |
| 453 | + .scan(new ScanOptions.ScanOptionsBuilder().match(patternKey).count(1000).build()); | |
| 454 | + int tmpIndex = 0; | |
| 455 | + int startIndex = (pageNum - 1) * pageSize; | |
| 456 | + int end = pageNum * pageSize; | |
| 457 | + while (cursor.hasNext()) { | |
| 458 | + if (tmpIndex >= startIndex && tmpIndex < end) { | |
| 459 | + binaryKeys.add(new String(cursor.next())); | |
| 460 | + tmpIndex++; | |
| 461 | + continue; | |
| 462 | + } | |
| 463 | + | |
| 464 | + // 获取到满足条件的数据后,就可以退出了 | |
| 465 | + if (tmpIndex >= end) { | |
| 466 | + break; | |
| 467 | + } | |
| 468 | + | |
| 469 | + tmpIndex++; | |
| 470 | + cursor.next(); | |
| 471 | + } | |
| 472 | + connection.close(); | |
| 473 | + return binaryKeys; | |
| 474 | + } | |
| 475 | + }); | |
| 476 | + | |
| 477 | + List<String> result = new ArrayList<String>(pageSize); | |
| 478 | + result.addAll(execute); | |
| 479 | + return result; | |
| 480 | + } | |
| 481 | + | |
| 482 | +} | ... | ... |
cloud/autho/src/main/java/com/sincere/autho/control/UserController.java
0 → 100644
| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | +package com.sincere.autho.control; | |
| 2 | + | |
| 3 | +import org.springframework.web.bind.annotation.GetMapping; | |
| 4 | +import org.springframework.web.bind.annotation.RestController; | |
| 5 | + | |
| 6 | +import java.security.Principal; | |
| 7 | + | |
| 8 | +@RestController | |
| 9 | +public class UserController { | |
| 10 | + | |
| 11 | + @GetMapping("/user") | |
| 12 | + public Principal user(Principal user){ | |
| 13 | + return user; | |
| 14 | + } | |
| 15 | + | |
| 16 | +} | ... | ... |
cloud/autho/src/main/java/com/sincere/autho/handler/ExceptionHandlerAdvice.java
0 → 100644
| ... | ... | @@ -0,0 +1,63 @@ |
| 1 | +package com.sincere.autho.handler; | |
| 2 | + | |
| 3 | +import io.grpc.StatusRuntimeException; | |
| 4 | +import org.springframework.http.HttpStatus; | |
| 5 | +import org.springframework.security.access.AccessDeniedException; | |
| 6 | +import org.springframework.web.bind.annotation.ExceptionHandler; | |
| 7 | +import org.springframework.web.bind.annotation.ResponseStatus; | |
| 8 | +import org.springframework.web.bind.annotation.RestControllerAdvice; | |
| 9 | + | |
| 10 | +import java.util.HashMap; | |
| 11 | +import java.util.Map; | |
| 12 | + | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * @author 作者 owen E-mail: 624191343@qq.com | |
| 16 | + * @version 创建时间:2017年11月12日 上午22:57:51 | |
| 17 | + * 异常通用处理 | |
| 18 | +*/ | |
| 19 | +@RestControllerAdvice | |
| 20 | +public class ExceptionHandlerAdvice { | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * IllegalArgumentException异常处理返回json | |
| 24 | + * 状态码:400 | |
| 25 | + * @param exception | |
| 26 | + * @return | |
| 27 | + */ | |
| 28 | + @ExceptionHandler({ IllegalArgumentException.class }) | |
| 29 | + @ResponseStatus(HttpStatus.BAD_REQUEST) | |
| 30 | + public Map<String, Object> badRequestException(IllegalArgumentException exception) { | |
| 31 | + Map<String, Object> data = new HashMap<>(); | |
| 32 | + data.put("resp_code", HttpStatus.BAD_REQUEST.value()); | |
| 33 | + data.put("resp_msg", exception.getMessage()); | |
| 34 | + | |
| 35 | + return data; | |
| 36 | + } | |
| 37 | + /** | |
| 38 | + * AccessDeniedException异常处理返回json | |
| 39 | + * 状态码:403 | |
| 40 | + * @param exception | |
| 41 | + * @return | |
| 42 | + */ | |
| 43 | + @ExceptionHandler({ AccessDeniedException.class }) | |
| 44 | + @ResponseStatus(HttpStatus.FORBIDDEN) | |
| 45 | + public Map<String, Object> badMethodExpressException(AccessDeniedException exception) { | |
| 46 | + Map<String, Object> data = new HashMap<>(); | |
| 47 | + data.put("resp_code", HttpStatus.FORBIDDEN.value()); | |
| 48 | + data.put("resp_msg", exception.getMessage()); | |
| 49 | + | |
| 50 | + return data; | |
| 51 | + } | |
| 52 | + @ExceptionHandler({ StatusRuntimeException.class }) | |
| 53 | + @ResponseStatus(HttpStatus.BAD_REQUEST) | |
| 54 | + public Map<String, Object> badRequestException(StatusRuntimeException exception) { | |
| 55 | + Map<String, Object> data = new HashMap<>(); | |
| 56 | + data.put("resp_code", HttpStatus.INTERNAL_SERVER_ERROR.value()); | |
| 57 | + data.put("resp_msg", exception.getMessage()); | |
| 58 | + | |
| 59 | + return data; | |
| 60 | + } | |
| 61 | + | |
| 62 | + | |
| 63 | +} | ... | ... |
cloud/autho/src/main/java/com/sincere/autho/handler/OauthLogoutHandler.java
0 → 100644
| ... | ... | @@ -0,0 +1,90 @@ |
| 1 | +package com.sincere.autho.handler; | |
| 2 | + | |
| 3 | +import org.slf4j.Logger; | |
| 4 | +import org.slf4j.LoggerFactory; | |
| 5 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 6 | +import org.springframework.security.core.Authentication; | |
| 7 | +import org.springframework.security.oauth2.common.OAuth2AccessToken; | |
| 8 | +import org.springframework.security.oauth2.common.OAuth2RefreshToken; | |
| 9 | +import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; | |
| 10 | +import org.springframework.security.oauth2.provider.token.TokenStore; | |
| 11 | +import org.springframework.security.web.authentication.logout.LogoutHandler; | |
| 12 | +import org.springframework.util.Assert; | |
| 13 | + | |
| 14 | +import javax.servlet.http.HttpServletRequest; | |
| 15 | +import javax.servlet.http.HttpServletResponse; | |
| 16 | +import java.util.Enumeration; | |
| 17 | + | |
| 18 | +/** | |
| 19 | + * @author keets | |
| 20 | + * @date 2017/10/17 | |
| 21 | + */ | |
| 22 | +public class OauthLogoutHandler implements LogoutHandler { | |
| 23 | + | |
| 24 | + private static final Logger logger = LoggerFactory.getLogger(OauthLogoutHandler.class); | |
| 25 | + | |
| 26 | + @Autowired | |
| 27 | + private TokenStore tokenStore; | |
| 28 | + | |
| 29 | + @Override | |
| 30 | + public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) { | |
| 31 | + Assert.notNull(tokenStore, "tokenStore must be set"); | |
| 32 | + String token = extractToken(request); | |
| 33 | + if(token!=null || !"".equals(token)){ | |
| 34 | + OAuth2AccessToken existingAccessToken = tokenStore.readAccessToken(token); | |
| 35 | + OAuth2RefreshToken refreshToken; | |
| 36 | + if (existingAccessToken != null) { | |
| 37 | + if (existingAccessToken.getRefreshToken() != null) { | |
| 38 | + logger.info("remove refreshToken!", existingAccessToken.getRefreshToken()); | |
| 39 | + refreshToken = existingAccessToken.getRefreshToken(); | |
| 40 | + tokenStore.removeRefreshToken(refreshToken); | |
| 41 | + } | |
| 42 | + logger.info("remove existingAccessToken!", existingAccessToken); | |
| 43 | + tokenStore.removeAccessToken(existingAccessToken); | |
| 44 | + } | |
| 45 | + return; | |
| 46 | + } | |
| 47 | + | |
| 48 | + } | |
| 49 | + | |
| 50 | + protected String extractToken(HttpServletRequest request) { | |
| 51 | + // first check the header... | |
| 52 | + String token = extractHeaderToken(request); | |
| 53 | + | |
| 54 | + // bearer type allows a request parameter as well | |
| 55 | + if (token == null) { | |
| 56 | + logger.debug("Token not found in headers. Trying request parameters."); | |
| 57 | + token = request.getParameter(OAuth2AccessToken.ACCESS_TOKEN); | |
| 58 | + if (token == null) { | |
| 59 | + logger.debug("Token not found in request parameters. Not an OAuth2 request."); | |
| 60 | + } else { | |
| 61 | + request.setAttribute(OAuth2AuthenticationDetails.ACCESS_TOKEN_TYPE, OAuth2AccessToken.BEARER_TYPE); | |
| 62 | + } | |
| 63 | + } | |
| 64 | + | |
| 65 | + return token; | |
| 66 | + } | |
| 67 | + | |
| 68 | + protected String extractHeaderToken(HttpServletRequest request) { | |
| 69 | + Enumeration<String> headers = request.getHeaders("Authorization"); | |
| 70 | + while (headers.hasMoreElements()) { // typically there is only one (most | |
| 71 | + // servers enforce that) | |
| 72 | + String value = headers.nextElement(); | |
| 73 | + if ((value.toLowerCase().startsWith(OAuth2AccessToken.BEARER_TYPE.toLowerCase()))) { | |
| 74 | + String authHeaderValue = value.substring(OAuth2AccessToken.BEARER_TYPE.length()).trim(); | |
| 75 | + // Add this here for the auth details later. Would be better to | |
| 76 | + // change the signature of this method. | |
| 77 | + request.setAttribute(OAuth2AuthenticationDetails.ACCESS_TOKEN_TYPE, | |
| 78 | + value.substring(0, OAuth2AccessToken.BEARER_TYPE.length()).trim()); | |
| 79 | + int commaIndex = authHeaderValue.indexOf(','); | |
| 80 | + if (commaIndex > 0) { | |
| 81 | + authHeaderValue = authHeaderValue.substring(0, commaIndex); | |
| 82 | + } | |
| 83 | + return authHeaderValue; | |
| 84 | + } | |
| 85 | + } | |
| 86 | + | |
| 87 | + return null; | |
| 88 | + } | |
| 89 | + | |
| 90 | +} | ... | ... |
cloud/autho/src/main/java/com/sincere/autho/log/dao/LogDao.java
0 → 100644
| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | +package com.sincere.autho.log.dao; | |
| 2 | + | |
| 3 | +import com.sincere.common.model.log.SysLog; | |
| 4 | +import org.apache.ibatis.annotations.Insert; | |
| 5 | +import org.apache.ibatis.annotations.Mapper; | |
| 6 | + | |
| 7 | +@Mapper | |
| 8 | +public interface LogDao { | |
| 9 | + | |
| 10 | + @Insert("insert into sys_log(username, module, params, remark, flag, createTime) values(#{username}, #{module}, #{params}, #{remark}, #{flag}, #{createTime})") | |
| 11 | + int save(SysLog log); | |
| 12 | + | |
| 13 | +} | ... | ... |
cloud/autho/src/main/java/com/sincere/autho/log/service/LogService.java
0 → 100644
cloud/autho/src/main/java/com/sincere/autho/log/service/impl/LogServiceImpl.java
0 → 100644
| ... | ... | @@ -0,0 +1,34 @@ |
| 1 | +package com.sincere.autho.log.service.impl; | |
| 2 | + | |
| 3 | +import com.sincere.autho.annotation.datasource.DataSource; | |
| 4 | +import com.sincere.autho.log.dao.LogDao; | |
| 5 | +import com.sincere.autho.log.service.LogService; | |
| 6 | +import com.sincere.common.model.log.SysLog; | |
| 7 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 8 | +import org.springframework.scheduling.annotation.Async; | |
| 9 | +import org.springframework.stereotype.Service; | |
| 10 | + | |
| 11 | +import java.util.Date; | |
| 12 | + | |
| 13 | +@Service | |
| 14 | +public class LogServiceImpl implements LogService { | |
| 15 | + | |
| 16 | + @Autowired | |
| 17 | + private LogDao logDao; | |
| 18 | + | |
| 19 | + @Async | |
| 20 | + @Override | |
| 21 | + @DataSource(name="log") | |
| 22 | + public void save(SysLog log) { | |
| 23 | + if (log.getCreateTime() == null) { | |
| 24 | + log.setCreateTime(new Date()); | |
| 25 | + } | |
| 26 | + if (log.getFlag() == null) { | |
| 27 | + log.setFlag(Boolean.TRUE); | |
| 28 | + } | |
| 29 | + | |
| 30 | + logDao.save(log); | |
| 31 | + } | |
| 32 | + | |
| 33 | + | |
| 34 | +} | ... | ... |
cloud/autho/src/main/java/com/sincere/autho/service/RedisAuthorizationCodeServices.java
0 → 100644
| ... | ... | @@ -0,0 +1,58 @@ |
| 1 | +package com.sincere.autho.service; | |
| 2 | + | |
| 3 | +import org.springframework.data.redis.core.RedisTemplate; | |
| 4 | +import org.springframework.security.oauth2.provider.OAuth2Authentication; | |
| 5 | +import org.springframework.security.oauth2.provider.code.RandomValueAuthorizationCodeServices; | |
| 6 | + | |
| 7 | +import java.util.concurrent.TimeUnit; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * JdbcAuthorizationCodeServices替换 | |
| 11 | + */ | |
| 12 | +public class RedisAuthorizationCodeServices extends RandomValueAuthorizationCodeServices { | |
| 13 | + | |
| 14 | + private RedisTemplate<String,Object> redisTemplate ; | |
| 15 | + | |
| 16 | + | |
| 17 | + public RedisTemplate<String, Object> getRedisTemplate() { | |
| 18 | + return redisTemplate; | |
| 19 | + } | |
| 20 | + | |
| 21 | + public void setRedisTemplate(RedisTemplate<String, Object> redisTemplate) { | |
| 22 | + this.redisTemplate = redisTemplate; | |
| 23 | + } | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 替换JdbcAuthorizationCodeServices的存储策略 | |
| 27 | + * 将存储code到redis,并设置过期时间,10分钟<br> | |
| 28 | + */ | |
| 29 | + @Override | |
| 30 | + protected void store(String code, OAuth2Authentication authentication) { | |
| 31 | + | |
| 32 | + redisTemplate.opsForValue().set(redisKey(code), authentication, 10, TimeUnit.MINUTES); | |
| 33 | + | |
| 34 | + | |
| 35 | + } | |
| 36 | + | |
| 37 | + @Override | |
| 38 | + protected OAuth2Authentication remove(final String code) { | |
| 39 | + | |
| 40 | + String codeKey =redisKey(code) ; | |
| 41 | + | |
| 42 | + OAuth2Authentication token = (OAuth2Authentication) redisTemplate.opsForValue().get(codeKey) ; | |
| 43 | + | |
| 44 | + this.redisTemplate.delete(codeKey); | |
| 45 | + | |
| 46 | + return token; | |
| 47 | + } | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * redis中 code key的前缀 | |
| 51 | + * | |
| 52 | + * @param code | |
| 53 | + * @return | |
| 54 | + */ | |
| 55 | + private String redisKey(String code) { | |
| 56 | + return "oauth:code:" + code; | |
| 57 | + } | |
| 58 | +} | ... | ... |
cloud/autho/src/main/java/com/sincere/autho/service/RedisClientDetailsService.java
0 → 100644
| ... | ... | @@ -0,0 +1,153 @@ |
| 1 | +package com.sincere.autho.service; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson.JSONObject; | |
| 4 | +import org.apache.commons.lang.StringUtils; | |
| 5 | +import org.slf4j.Logger; | |
| 6 | +import org.slf4j.LoggerFactory; | |
| 7 | +import org.springframework.data.redis.core.RedisTemplate; | |
| 8 | +import org.springframework.security.oauth2.common.exceptions.InvalidClientException; | |
| 9 | +import org.springframework.security.oauth2.provider.ClientDetails; | |
| 10 | +import org.springframework.security.oauth2.provider.NoSuchClientException; | |
| 11 | +import org.springframework.security.oauth2.provider.client.BaseClientDetails; | |
| 12 | +import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService; | |
| 13 | +import org.springframework.util.CollectionUtils; | |
| 14 | + | |
| 15 | +import javax.sql.DataSource; | |
| 16 | +import java.util.List; | |
| 17 | + | |
| 18 | + | |
| 19 | +/** | |
| 20 | + * @author owen 624191343@qq.com | |
| 21 | + * @version 创建时间:2017年11月12日 上午22:57:51 | |
| 22 | + * 类说明 | |
| 23 | + * 将oauth_client_details表数据缓存到redis,这里做个缓存优化 | |
| 24 | + * layui模块中有对oauth_client_details的crud, 注意同步redis的数据 | |
| 25 | + * 注意对oauth_client_details清楚redis db部分数据的清空 | |
| 26 | + */ | |
| 27 | + | |
| 28 | +public class RedisClientDetailsService extends JdbcClientDetailsService { | |
| 29 | + | |
| 30 | + | |
| 31 | + // 扩展 默认的 ClientDetailsService, 增加逻辑删除判断( status = 1) | |
| 32 | + private static final String SELECT_CLIENT_DETAILS_SQL = "select client_id, client_secret, resource_ids, scope, authorized_grant_types, " + | |
| 33 | + "web_server_redirect_uri, authorities, access_token_validity, refresh_token_validity, additional_information, autoapprove " + | |
| 34 | + "from oauth_client_details where client_id = ? and `status` = 1 "; | |
| 35 | + | |
| 36 | + | |
| 37 | + private static final String SELECT_FIND_STATEMENT = "select client_id, client_secret,resource_ids, scope, " | |
| 38 | + + "authorized_grant_types, web_server_redirect_uri, authorities, access_token_validity, " | |
| 39 | + + "refresh_token_validity, additional_information, autoapprove from oauth_client_details where `status` = 1 order by client_id " ; | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * 缓存client的redis key,这里是hash结构存储 | |
| 43 | + */ | |
| 44 | + private static final String CACHE_CLIENT_KEY = "oauth_client_details"; | |
| 45 | + | |
| 46 | + private Logger logger = LoggerFactory.getLogger(RedisClientDetailsService.class) ; | |
| 47 | + | |
| 48 | + private RedisTemplate<String,Object> redisTemplate ; | |
| 49 | + | |
| 50 | + public RedisTemplate<String, Object> getRedisTemplate() { | |
| 51 | + return redisTemplate; | |
| 52 | + } | |
| 53 | + | |
| 54 | + public void setRedisTemplate(RedisTemplate<String, Object> redisTemplate) { | |
| 55 | + this.redisTemplate = redisTemplate; | |
| 56 | + } | |
| 57 | + | |
| 58 | + public RedisClientDetailsService(DataSource dataSource) { | |
| 59 | + super(dataSource); | |
| 60 | + setSelectClientDetailsSql(SELECT_CLIENT_DETAILS_SQL) ; | |
| 61 | + setFindClientDetailsSql(SELECT_FIND_STATEMENT) ; | |
| 62 | + } | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + @Override | |
| 67 | + public ClientDetails loadClientByClientId(String clientId) throws InvalidClientException { | |
| 68 | + ClientDetails clientDetails = null; | |
| 69 | + | |
| 70 | + // 先从redis获取 | |
| 71 | + String value = (String) redisTemplate.boundHashOps(CACHE_CLIENT_KEY).get(clientId); | |
| 72 | + if (StringUtils.isBlank(value)) { | |
| 73 | + clientDetails = cacheAndGetClient(clientId); | |
| 74 | + } else { | |
| 75 | + clientDetails = JSONObject.parseObject(value, BaseClientDetails.class); | |
| 76 | + } | |
| 77 | + | |
| 78 | + return clientDetails; | |
| 79 | + } | |
| 80 | + | |
| 81 | + /** | |
| 82 | + * 缓存client并返回client | |
| 83 | + * | |
| 84 | + * @param clientId | |
| 85 | + * @return | |
| 86 | + */ | |
| 87 | + private ClientDetails cacheAndGetClient(String clientId) { | |
| 88 | + // 从数据库读取 | |
| 89 | + ClientDetails clientDetails = null ; | |
| 90 | + try { | |
| 91 | + clientDetails = super.loadClientByClientId(clientId); | |
| 92 | + if (clientDetails != null) { | |
| 93 | + // 写入redis缓存 | |
| 94 | + redisTemplate.boundHashOps(CACHE_CLIENT_KEY).put(clientId, JSONObject.toJSONString(clientDetails)); | |
| 95 | + logger.info("缓存clientId:{},{}", clientId, clientDetails); | |
| 96 | + } | |
| 97 | + }catch (NoSuchClientException e){ | |
| 98 | + logger.info("clientId:{},{}", clientId, clientId ); | |
| 99 | + }catch (InvalidClientException e) { | |
| 100 | + // TODO Auto-generated catch block | |
| 101 | + e.printStackTrace(); | |
| 102 | + } | |
| 103 | + | |
| 104 | + return clientDetails; | |
| 105 | + } | |
| 106 | + | |
| 107 | + @Override | |
| 108 | + public void updateClientDetails(ClientDetails clientDetails) throws NoSuchClientException { | |
| 109 | + super.updateClientDetails(clientDetails); | |
| 110 | + cacheAndGetClient(clientDetails.getClientId()); | |
| 111 | + } | |
| 112 | + | |
| 113 | + @Override | |
| 114 | + public void updateClientSecret(String clientId, String secret) throws NoSuchClientException { | |
| 115 | + super.updateClientSecret(clientId, secret); | |
| 116 | + cacheAndGetClient(clientId); | |
| 117 | + } | |
| 118 | + | |
| 119 | + @Override | |
| 120 | + public void removeClientDetails(String clientId) throws NoSuchClientException { | |
| 121 | + super.removeClientDetails(clientId); | |
| 122 | + removeRedisCache(clientId); | |
| 123 | + } | |
| 124 | + | |
| 125 | + /** | |
| 126 | + * 删除redis缓存 | |
| 127 | + * | |
| 128 | + * @param clientId | |
| 129 | + */ | |
| 130 | + private void removeRedisCache(String clientId) { | |
| 131 | + redisTemplate.boundHashOps(CACHE_CLIENT_KEY).delete(clientId); | |
| 132 | + } | |
| 133 | + | |
| 134 | + /** | |
| 135 | + * 将oauth_client_details全表刷入redis | |
| 136 | + */ | |
| 137 | + public void loadAllClientToCache() { | |
| 138 | + if (redisTemplate.hasKey(CACHE_CLIENT_KEY)) { | |
| 139 | + return; | |
| 140 | + } | |
| 141 | + logger.info("将oauth_client_details全表刷入redis"); | |
| 142 | + | |
| 143 | + List<ClientDetails> list = super.listClientDetails(); | |
| 144 | + if (CollectionUtils.isEmpty(list)) { | |
| 145 | + logger.error("oauth_client_details表数据为空,请检查"); | |
| 146 | + return; | |
| 147 | + } | |
| 148 | + | |
| 149 | + list.parallelStream().forEach(client -> { | |
| 150 | + redisTemplate.boundHashOps(CACHE_CLIENT_KEY).put(client.getClientId(), JSONObject.toJSONString(client)); | |
| 151 | + }); | |
| 152 | + } | |
| 153 | +} | ... | ... |
cloud/autho/src/main/java/com/sincere/autho/token/RedisTemplateTokenStore.java
0 → 100644
| ... | ... | @@ -0,0 +1,331 @@ |
| 1 | +package com.sincere.autho.token; | |
| 2 | + | |
| 3 | +import com.sincere.common.model.system.LoginAppUser; | |
| 4 | +import org.springframework.data.redis.core.RedisTemplate; | |
| 5 | +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | |
| 6 | +import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; | |
| 7 | +import org.springframework.security.oauth2.common.ExpiringOAuth2RefreshToken; | |
| 8 | +import org.springframework.security.oauth2.common.OAuth2AccessToken; | |
| 9 | +import org.springframework.security.oauth2.common.OAuth2RefreshToken; | |
| 10 | +import org.springframework.security.oauth2.provider.OAuth2Authentication; | |
| 11 | +import org.springframework.security.oauth2.provider.token.AuthenticationKeyGenerator; | |
| 12 | +import org.springframework.security.oauth2.provider.token.DefaultAuthenticationKeyGenerator; | |
| 13 | +import org.springframework.security.oauth2.provider.token.TokenStore; | |
| 14 | + | |
| 15 | +import java.time.Instant; | |
| 16 | +import java.time.LocalDateTime; | |
| 17 | +import java.time.ZoneId; | |
| 18 | +import java.util.*; | |
| 19 | +import java.util.concurrent.TimeUnit; | |
| 20 | + | |
| 21 | +/** | |
| 22 | + * @version redis集群存储token | |
| 23 | + */ | |
| 24 | + | |
| 25 | +public class RedisTemplateTokenStore implements TokenStore { | |
| 26 | + | |
| 27 | + private static final String ACCESS = "access:"; | |
| 28 | + private static final String AUTH_TO_ACCESS = "auth_to_access:"; | |
| 29 | + private static final String AUTH = "auth:"; | |
| 30 | + private static final String REFRESH_AUTH = "refresh_auth:"; | |
| 31 | + private static final String ACCESS_TO_REFRESH = "access_to_refresh:"; | |
| 32 | + private static final String REFRESH = "refresh:"; | |
| 33 | + private static final String REFRESH_TO_ACCESS = "refresh_to_access:"; | |
| 34 | + private static final String CLIENT_ID_TO_ACCESS = "client_id_to_access:"; | |
| 35 | + private static final String UNAME_TO_ACCESS = "uname_to_access:"; | |
| 36 | + private static final String TOKEN = "token:"; | |
| 37 | + | |
| 38 | + private RedisTemplate<String, Object> redisTemplate; | |
| 39 | + | |
| 40 | + public RedisTemplate<String, Object> getRedisTemplate() { | |
| 41 | + return redisTemplate; | |
| 42 | + } | |
| 43 | + | |
| 44 | + public void setRedisTemplate(RedisTemplate<String, Object> redisTemplate) { | |
| 45 | + this.redisTemplate = redisTemplate; | |
| 46 | + } | |
| 47 | + | |
| 48 | + private AuthenticationKeyGenerator authenticationKeyGenerator = new DefaultAuthenticationKeyGenerator(); | |
| 49 | + | |
| 50 | + public void setAuthenticationKeyGenerator(AuthenticationKeyGenerator authenticationKeyGenerator) { | |
| 51 | + this.authenticationKeyGenerator = authenticationKeyGenerator; | |
| 52 | + } | |
| 53 | + | |
| 54 | + public OAuth2AccessToken getAccessToken(OAuth2Authentication authentication) { | |
| 55 | + String key = authenticationKeyGenerator.extractKey(authentication); | |
| 56 | + OAuth2AccessToken accessToken = (OAuth2AccessToken) redisTemplate.opsForValue().get(AUTH_TO_ACCESS + key); | |
| 57 | + if (accessToken != null | |
| 58 | + && !key.equals(authenticationKeyGenerator.extractKey(readAuthentication(accessToken.getValue())))) { | |
| 59 | + // Keep the stores consistent (maybe the same user is represented by | |
| 60 | + // this authentication but the details | |
| 61 | + // have changed) | |
| 62 | + storeAccessToken(accessToken, authentication); | |
| 63 | + } | |
| 64 | + return accessToken; | |
| 65 | + } | |
| 66 | + | |
| 67 | + public OAuth2Authentication readAuthentication(OAuth2AccessToken token) { | |
| 68 | + return readAuthentication(token.getValue()); | |
| 69 | + } | |
| 70 | + | |
| 71 | + public OAuth2Authentication readAuthentication(String token) { | |
| 72 | + return (OAuth2Authentication) this.redisTemplate.opsForValue().get(AUTH + token); | |
| 73 | + } | |
| 74 | + | |
| 75 | + public OAuth2Authentication readAuthenticationForRefreshToken(OAuth2RefreshToken token) { | |
| 76 | + return readAuthenticationForRefreshToken(token.getValue()); | |
| 77 | + } | |
| 78 | + | |
| 79 | + public OAuth2Authentication readAuthenticationForRefreshToken(String token) { | |
| 80 | + return (OAuth2Authentication) this.redisTemplate.opsForValue().get(REFRESH_AUTH + token); | |
| 81 | + } | |
| 82 | + | |
| 83 | + public void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) { | |
| 84 | + | |
| 85 | + OAuth2AccessToken existingAccessToken = this.getAccessToken(authentication); | |
| 86 | + | |
| 87 | + this.redisTemplate.opsForValue().set(ACCESS + token.getValue(), token); | |
| 88 | + this.redisTemplate.opsForValue().set(AUTH + token.getValue(), authentication); | |
| 89 | + this.redisTemplate.opsForValue().set(AUTH_TO_ACCESS + authenticationKeyGenerator.extractKey(authentication), | |
| 90 | + token); | |
| 91 | + | |
| 92 | + Map<String, Object> params = new HashMap<>(); | |
| 93 | + | |
| 94 | + params.put("clientId", authentication.getOAuth2Request().getClientId()); | |
| 95 | + | |
| 96 | + if (authentication.getUserAuthentication() instanceof UsernamePasswordAuthenticationToken) { | |
| 97 | + UsernamePasswordAuthenticationToken authenticationToken = (UsernamePasswordAuthenticationToken) authentication | |
| 98 | + .getUserAuthentication(); | |
| 99 | + LoginAppUser appUser = (LoginAppUser) authenticationToken.getPrincipal(); | |
| 100 | + params.put("username", appUser.getUsername()); | |
| 101 | + params.put("authorities", appUser.getAuthorities()); | |
| 102 | + } | |
| 103 | + | |
| 104 | + if (!params.isEmpty()) { | |
| 105 | + this.redisTemplate.opsForValue().set(TOKEN + token.getValue(), params); | |
| 106 | + } | |
| 107 | + | |
| 108 | + if (!authentication.isClientOnly()) { | |
| 109 | + if (existingAccessToken != null) { | |
| 110 | + if (!existingAccessToken.isExpired()) { | |
| 111 | + int seconds = token.getExpiresIn(); | |
| 112 | + redisTemplate.expire(UNAME_TO_ACCESS + authentication.getOAuth2Request().getClientId(), seconds, | |
| 113 | + TimeUnit.SECONDS); | |
| 114 | + } else { | |
| 115 | + redisTemplate.opsForList().rightPush(UNAME_TO_ACCESS + getApprovalKey(authentication), token); | |
| 116 | + } | |
| 117 | + } else { | |
| 118 | + redisTemplate.opsForList().rightPush(UNAME_TO_ACCESS + getApprovalKey(authentication), token); | |
| 119 | + } | |
| 120 | + | |
| 121 | + } | |
| 122 | + | |
| 123 | + if (existingAccessToken != null) { | |
| 124 | + if (!existingAccessToken.isExpired()) { | |
| 125 | + int seconds = token.getExpiresIn(); | |
| 126 | + redisTemplate.expire(CLIENT_ID_TO_ACCESS + authentication.getOAuth2Request().getClientId(), seconds, | |
| 127 | + TimeUnit.SECONDS); | |
| 128 | + | |
| 129 | + } else { | |
| 130 | + redisTemplate.opsForList() | |
| 131 | + .rightPush(CLIENT_ID_TO_ACCESS + authentication.getOAuth2Request().getClientId(), token); | |
| 132 | + } | |
| 133 | + } else { | |
| 134 | + redisTemplate.opsForList().rightPush(CLIENT_ID_TO_ACCESS + authentication.getOAuth2Request().getClientId(), | |
| 135 | + token); | |
| 136 | + } | |
| 137 | + | |
| 138 | + if (token.getExpiration() != null) { | |
| 139 | + | |
| 140 | + int seconds = token.getExpiresIn(); | |
| 141 | + redisTemplate.expire(ACCESS + token.getValue(), seconds, TimeUnit.SECONDS); | |
| 142 | + redisTemplate.expire(AUTH + token.getValue(), seconds, TimeUnit.SECONDS); | |
| 143 | + redisTemplate.expire(TOKEN + token.getValue(), seconds, TimeUnit.SECONDS); | |
| 144 | + redisTemplate.expire(AUTH_TO_ACCESS + authenticationKeyGenerator.extractKey(authentication), seconds, | |
| 145 | + TimeUnit.SECONDS); | |
| 146 | + redisTemplate.expire(CLIENT_ID_TO_ACCESS + authentication.getOAuth2Request().getClientId(), seconds, | |
| 147 | + TimeUnit.SECONDS); | |
| 148 | + redisTemplate.expire(UNAME_TO_ACCESS + getApprovalKey(authentication), seconds, TimeUnit.SECONDS); | |
| 149 | + } | |
| 150 | + | |
| 151 | + OAuth2RefreshToken refreshToken = token.getRefreshToken(); | |
| 152 | + | |
| 153 | + if (token.getRefreshToken() != null && token.getRefreshToken().getValue() != null) { | |
| 154 | + this.redisTemplate.opsForValue().set(REFRESH_TO_ACCESS + token.getRefreshToken().getValue(), | |
| 155 | + token.getValue()); | |
| 156 | + this.redisTemplate.opsForValue().set(ACCESS_TO_REFRESH + token.getValue(), | |
| 157 | + token.getRefreshToken().getValue()); | |
| 158 | + | |
| 159 | + if (refreshToken instanceof ExpiringOAuth2RefreshToken) { | |
| 160 | + ExpiringOAuth2RefreshToken expiringRefreshToken = (ExpiringOAuth2RefreshToken) refreshToken; | |
| 161 | + Date expiration = expiringRefreshToken.getExpiration(); | |
| 162 | + if (expiration != null) { | |
| 163 | + int seconds = Long.valueOf((expiration.getTime() - System.currentTimeMillis()) / 1000L).intValue(); | |
| 164 | + | |
| 165 | + redisTemplate.expire(REFRESH_TO_ACCESS + token.getRefreshToken().getValue(), seconds, | |
| 166 | + TimeUnit.SECONDS); | |
| 167 | + redisTemplate.expire(ACCESS_TO_REFRESH + token.getValue(), seconds, TimeUnit.SECONDS); | |
| 168 | + | |
| 169 | + } | |
| 170 | + } | |
| 171 | + | |
| 172 | + } | |
| 173 | + } | |
| 174 | + | |
| 175 | + private String getApprovalKey(OAuth2Authentication authentication) { | |
| 176 | + String userName = authentication.getUserAuthentication() == null ? "" | |
| 177 | + : authentication.getUserAuthentication().getName(); | |
| 178 | + return getApprovalKey(authentication.getOAuth2Request().getClientId(), userName); | |
| 179 | + } | |
| 180 | + | |
| 181 | + private String getApprovalKey(String clientId, String userName) { | |
| 182 | + return clientId + (userName == null ? "" : ":" + userName); | |
| 183 | + } | |
| 184 | + | |
| 185 | + public void removeAccessToken(OAuth2AccessToken accessToken) { | |
| 186 | + removeAccessToken(accessToken.getValue()); | |
| 187 | + } | |
| 188 | + | |
| 189 | + public OAuth2AccessToken readAccessToken(String tokenValue) { | |
| 190 | + | |
| 191 | + OAuth2Authentication oauth2Authentication = (OAuth2Authentication) this.redisTemplate.opsForValue() | |
| 192 | + .get(AUTH + tokenValue); | |
| 193 | + OAuth2AccessToken oauth2AccessToken = (OAuth2AccessToken) this.redisTemplate.opsForValue() | |
| 194 | + .get(ACCESS + tokenValue); | |
| 195 | + if (oauth2Authentication != null) { | |
| 196 | + String auth_to_access = authenticationKeyGenerator.extractKey(oauth2Authentication); | |
| 197 | + if (oauth2AccessToken != null) { | |
| 198 | + if (oauth2AccessToken.getExpiresIn() < 180) { | |
| 199 | + | |
| 200 | + if (oauth2AccessToken instanceof DefaultOAuth2AccessToken) { | |
| 201 | + DefaultOAuth2AccessToken token = (DefaultOAuth2AccessToken) oauth2AccessToken; | |
| 202 | +// Calendar cal = Calendar.getInstance(); | |
| 203 | +// cal.add(Calendar.DATE, 30); | |
| 204 | +// Date date = cal.getTime(); | |
| 205 | + /** | |
| 206 | + * 自动续费 30分钟 | |
| 207 | + */ | |
| 208 | + LocalDateTime t1 = LocalDateTime.now().plusMinutes(30); | |
| 209 | + ZoneId zone = ZoneId.systemDefault(); | |
| 210 | + Instant instant = t1.atZone(zone).toInstant(); | |
| 211 | + Date date = Date.from(instant); | |
| 212 | + | |
| 213 | + token.setExpiration(date); | |
| 214 | + | |
| 215 | + int seconds = token.getExpiresIn(); | |
| 216 | + | |
| 217 | + this.redisTemplate.opsForValue().set(AUTH_TO_ACCESS + auth_to_access, token, seconds, | |
| 218 | + TimeUnit.SECONDS); | |
| 219 | + this.redisTemplate.opsForValue().set(ACCESS + token.getValue(), token, seconds, | |
| 220 | + TimeUnit.SECONDS); | |
| 221 | + | |
| 222 | + redisTemplate.expire(AUTH + token.getValue(), seconds, TimeUnit.SECONDS); | |
| 223 | + redisTemplate.expire(TOKEN + token.getValue(), seconds, TimeUnit.SECONDS); | |
| 224 | + | |
| 225 | + redisTemplate.expire( | |
| 226 | + CLIENT_ID_TO_ACCESS + oauth2Authentication.getOAuth2Request().getClientId(), seconds, | |
| 227 | + TimeUnit.SECONDS); | |
| 228 | + redisTemplate.expire(UNAME_TO_ACCESS + getApprovalKey(oauth2Authentication), seconds, | |
| 229 | + TimeUnit.SECONDS); | |
| 230 | + | |
| 231 | + } | |
| 232 | + | |
| 233 | + } | |
| 234 | + } | |
| 235 | + } | |
| 236 | + | |
| 237 | + return oauth2AccessToken; | |
| 238 | + } | |
| 239 | + | |
| 240 | + public void removeAccessToken(String tokenValue) { | |
| 241 | + OAuth2AccessToken removed = (OAuth2AccessToken) redisTemplate.opsForValue().get(ACCESS + tokenValue); | |
| 242 | + // Don't remove the refresh token - it's up to the caller to do that | |
| 243 | + OAuth2Authentication authentication = (OAuth2Authentication) this.redisTemplate.opsForValue() | |
| 244 | + .get(AUTH + tokenValue); | |
| 245 | + | |
| 246 | + this.redisTemplate.delete(AUTH + tokenValue); | |
| 247 | + redisTemplate.delete(ACCESS + tokenValue); | |
| 248 | + redisTemplate.delete(TOKEN + tokenValue); | |
| 249 | + this.redisTemplate.delete(ACCESS_TO_REFRESH + tokenValue); | |
| 250 | + | |
| 251 | + if (authentication != null) { | |
| 252 | + this.redisTemplate.delete(AUTH_TO_ACCESS + authenticationKeyGenerator.extractKey(authentication)); | |
| 253 | + | |
| 254 | + String clientId = authentication.getOAuth2Request().getClientId(); | |
| 255 | + | |
| 256 | + // redisTemplate.opsForList().rightPush("UNAME_TO_ACCESS:"+getApprovalKey(authentication), | |
| 257 | + // token) ; | |
| 258 | + redisTemplate.opsForList().leftPop(UNAME_TO_ACCESS + getApprovalKey(clientId, authentication.getName())); | |
| 259 | + | |
| 260 | + redisTemplate.opsForList().leftPop(CLIENT_ID_TO_ACCESS + clientId); | |
| 261 | + | |
| 262 | + this.redisTemplate.delete(AUTH_TO_ACCESS + authenticationKeyGenerator.extractKey(authentication)); | |
| 263 | + } | |
| 264 | + } | |
| 265 | + | |
| 266 | + public void storeRefreshToken(OAuth2RefreshToken refreshToken, OAuth2Authentication authentication) { | |
| 267 | + this.redisTemplate.opsForValue().set(REFRESH + refreshToken.getValue(), refreshToken); | |
| 268 | + this.redisTemplate.opsForValue().set(REFRESH_AUTH + refreshToken.getValue(), authentication); | |
| 269 | + } | |
| 270 | + | |
| 271 | + public OAuth2RefreshToken readRefreshToken(String tokenValue) { | |
| 272 | + return (OAuth2RefreshToken) this.redisTemplate.opsForValue().get(REFRESH + tokenValue); | |
| 273 | + } | |
| 274 | + | |
| 275 | + public void removeRefreshToken(OAuth2RefreshToken refreshToken) { | |
| 276 | + removeRefreshToken(refreshToken.getValue()); | |
| 277 | + } | |
| 278 | + | |
| 279 | + public void removeRefreshToken(String tokenValue) { | |
| 280 | + this.redisTemplate.delete(REFRESH + tokenValue); | |
| 281 | + this.redisTemplate.delete(REFRESH_AUTH + tokenValue); | |
| 282 | + this.redisTemplate.delete(REFRESH_TO_ACCESS + tokenValue); | |
| 283 | + } | |
| 284 | + | |
| 285 | + public void removeAccessTokenUsingRefreshToken(OAuth2RefreshToken refreshToken) { | |
| 286 | + removeAccessTokenUsingRefreshToken(refreshToken.getValue()); | |
| 287 | + } | |
| 288 | + | |
| 289 | + private void removeAccessTokenUsingRefreshToken(String refreshToken) { | |
| 290 | + | |
| 291 | + String token = (String) this.redisTemplate.opsForValue().get(REFRESH_TO_ACCESS + refreshToken); | |
| 292 | + | |
| 293 | + if (token != null) { | |
| 294 | + redisTemplate.delete(REFRESH_TO_ACCESS + refreshToken); | |
| 295 | + } | |
| 296 | + } | |
| 297 | + | |
| 298 | + public Collection<OAuth2AccessToken> findTokensByClientIdAndUserName(String clientId, String userName) { | |
| 299 | + List<Object> result = redisTemplate.opsForList().range(UNAME_TO_ACCESS + getApprovalKey(clientId, userName), 0, | |
| 300 | + -1); | |
| 301 | + | |
| 302 | + if (result == null || result.size() == 0) { | |
| 303 | + return Collections.<OAuth2AccessToken>emptySet(); | |
| 304 | + } | |
| 305 | + List<OAuth2AccessToken> accessTokens = new ArrayList<OAuth2AccessToken>(result.size()); | |
| 306 | + | |
| 307 | + for (Iterator<Object> it = result.iterator(); it.hasNext();) { | |
| 308 | + OAuth2AccessToken accessToken = (OAuth2AccessToken) it.next(); | |
| 309 | + accessTokens.add(accessToken); | |
| 310 | + } | |
| 311 | + | |
| 312 | + return Collections.<OAuth2AccessToken>unmodifiableCollection(accessTokens); | |
| 313 | + } | |
| 314 | + | |
| 315 | + public Collection<OAuth2AccessToken> findTokensByClientId(String clientId) { | |
| 316 | + List<Object> result = redisTemplate.opsForList().range((CLIENT_ID_TO_ACCESS + clientId), 0, -1); | |
| 317 | + | |
| 318 | + if (result == null || result.size() == 0) { | |
| 319 | + return Collections.<OAuth2AccessToken>emptySet(); | |
| 320 | + } | |
| 321 | + List<OAuth2AccessToken> accessTokens = new ArrayList<OAuth2AccessToken>(result.size()); | |
| 322 | + | |
| 323 | + for (Iterator<Object> it = result.iterator(); it.hasNext();) { | |
| 324 | + OAuth2AccessToken accessToken = (OAuth2AccessToken) it.next(); | |
| 325 | + accessTokens.add(accessToken); | |
| 326 | + } | |
| 327 | + | |
| 328 | + return Collections.<OAuth2AccessToken>unmodifiableCollection(accessTokens); | |
| 329 | + } | |
| 330 | + | |
| 331 | +} | ... | ... |
cloud/autho/src/main/java/com/sincere/autho/utils/SpringUtil.java
0 → 100644
| ... | ... | @@ -0,0 +1,35 @@ |
| 1 | +package com.sincere.autho.utils; | |
| 2 | + | |
| 3 | +import org.springframework.beans.BeansException; | |
| 4 | +import org.springframework.context.ApplicationContext; | |
| 5 | +import org.springframework.context.ApplicationContextAware; | |
| 6 | +import org.springframework.core.env.Environment; | |
| 7 | +import org.springframework.stereotype.Component; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * spring获取bean工具类 | |
| 11 | + * | |
| 12 | + * | |
| 13 | + */ | |
| 14 | +@Component | |
| 15 | +public class SpringUtil implements ApplicationContextAware { | |
| 16 | + | |
| 17 | + private static ApplicationContext applicationContext = null; | |
| 18 | + | |
| 19 | + @Override | |
| 20 | + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | |
| 21 | + SpringUtil.applicationContext = applicationContext; | |
| 22 | + } | |
| 23 | + | |
| 24 | + public static <T> T getBean(Class<T> cla) { | |
| 25 | + return applicationContext.getBean(cla); | |
| 26 | + } | |
| 27 | + | |
| 28 | + public static <T> T getBean(String name, Class<T> cal) { | |
| 29 | + return applicationContext.getBean(name, cal); | |
| 30 | + } | |
| 31 | + | |
| 32 | + public static String getProperty(String key) { | |
| 33 | + return applicationContext.getBean(Environment.class).getProperty(key); | |
| 34 | + } | |
| 35 | +} | ... | ... |
cloud/autho/src/main/java/com/sincere/autho/utils/SysUserUtil.java
0 → 100644
| ... | ... | @@ -0,0 +1,41 @@ |
| 1 | +package com.sincere.autho.utils; | |
| 2 | + | |
| 3 | +import com.sincere.common.model.system.LoginAppUser; | |
| 4 | +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | |
| 5 | +import org.springframework.security.core.Authentication; | |
| 6 | +import org.springframework.security.core.context.SecurityContextHolder; | |
| 7 | +import org.springframework.security.oauth2.provider.OAuth2Authentication; | |
| 8 | +import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * @author 作者 owen E-mail: 624191343@qq.com | |
| 12 | + * @version 创建时间:2017年11月12日 上午22:57:51 获取用户信息 | |
| 13 | + */ | |
| 14 | +public class SysUserUtil { | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * 获取登陆的 LoginAppUser | |
| 18 | + * | |
| 19 | + * @return | |
| 20 | + */ | |
| 21 | + @SuppressWarnings("rawtypes") | |
| 22 | + public static LoginAppUser getLoginAppUser() { | |
| 23 | + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | |
| 24 | + if (authentication instanceof OAuth2Authentication) { | |
| 25 | + OAuth2Authentication oAuth2Auth = (OAuth2Authentication) authentication; | |
| 26 | + authentication = oAuth2Auth.getUserAuthentication(); | |
| 27 | + | |
| 28 | + if (authentication instanceof UsernamePasswordAuthenticationToken) { | |
| 29 | + UsernamePasswordAuthenticationToken authenticationToken = (UsernamePasswordAuthenticationToken) authentication; | |
| 30 | + return (LoginAppUser) authenticationToken.getPrincipal(); | |
| 31 | + } else if (authentication instanceof PreAuthenticatedAuthenticationToken) { | |
| 32 | + // 刷新token方式 | |
| 33 | + PreAuthenticatedAuthenticationToken authenticationToken = (PreAuthenticatedAuthenticationToken) authentication; | |
| 34 | + return (LoginAppUser) authenticationToken.getPrincipal(); | |
| 35 | + | |
| 36 | + } | |
| 37 | + } | |
| 38 | + | |
| 39 | + return null; | |
| 40 | + } | |
| 41 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,96 @@ |
| 1 | +server: | |
| 2 | + port: 8763 | |
| 3 | + | |
| 4 | +spring: | |
| 5 | + application: | |
| 6 | + name: auth-server | |
| 7 | +session: | |
| 8 | + store-type: redis | |
| 9 | + datasource: | |
| 10 | + dynamic: | |
| 11 | + enable: true | |
| 12 | + druid: | |
| 13 | + # JDBC 配置(驱动类自动从url的mysql识别,数据源类型自动识别) | |
| 14 | + core: | |
| 15 | + url: jdbc:mysql://localhost/oauth-center?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false | |
| 16 | + username: root | |
| 17 | + password: root | |
| 18 | + driver-class-name: com.mysql.jdbc.Driver | |
| 19 | + log: | |
| 20 | + url: jdbc:mysql://59.110.164.254:3306/log-center?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false | |
| 21 | + username: root | |
| 22 | + password: root | |
| 23 | + driver-class-name: com.mysql.jdbc.Driver | |
| 24 | + #连接池配置(通常来说,只需要修改initialSize、minIdle、maxActive | |
| 25 | + initial-size: 1 | |
| 26 | + max-active: 20 | |
| 27 | + min-idle: 1 | |
| 28 | + # 配置获取连接等待超时的时间 | |
| 29 | + max-wait: 60000 | |
| 30 | + #打开PSCache,并且指定每个连接上PSCache的大小 | |
| 31 | + pool-prepared-statements: true | |
| 32 | + max-pool-prepared-statement-per-connection-size: 20 | |
| 33 | + validation-query: SELECT 'x' | |
| 34 | + test-on-borrow: false | |
| 35 | + test-on-return: false | |
| 36 | + test-while-idle: true | |
| 37 | + #配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 | |
| 38 | + time-between-eviction-runs-millis: 60000 | |
| 39 | + #配置一个连接在池中最小生存的时间,单位是毫秒 | |
| 40 | + min-evictable-idle-time-millis: 300000 | |
| 41 | + filters: stat,wall | |
| 42 | + # WebStatFilter配置,说明请参考Druid Wiki,配置_配置WebStatFilter | |
| 43 | + #是否启用StatFilter默认值true | |
| 44 | + web-stat-filter.enabled: true | |
| 45 | + web-stat-filter.url-pattern: /* | |
| 46 | + web-stat-filter.exclusions: "*.js , *.gif ,*.jpg ,*.png ,*.css ,*.ico , /druid/*" | |
| 47 | + web-stat-filter.session-stat-max-count: 1000 | |
| 48 | + web-stat-filter.profile-enable: true | |
| 49 | + # StatViewServlet配置 | |
| 50 | + #展示Druid的统计信息,StatViewServlet的用途包括:1.提供监控信息展示的html页面2.提供监控信息的JSON API | |
| 51 | + #是否启用StatViewServlet默认值true | |
| 52 | + stat-view-servlet.enabled: true | |
| 53 | + #根据配置中的url-pattern来访问内置监控页面,如果是上面的配置,内置监控页面的首页是/druid/index.html例如: | |
| 54 | + #http://110.76.43.235:9000/druid/index.html | |
| 55 | + #http://110.76.43.235:8080/mini-web/druid/index.html | |
| 56 | + stat-view-servlet.url-pattern: /druid/* | |
| 57 | + #允许清空统计数据 | |
| 58 | + stat-view-servlet.reset-enable: true | |
| 59 | + stat-view-servlet.login-username: admin | |
| 60 | + stat-view-servlet.login-password: admin | |
| 61 | + #StatViewSerlvet展示出来的监控信息比较敏感,是系统运行的内部情况,如果你需要做访问控制,可以配置allow和deny这两个参数 | |
| 62 | + #deny优先于allow,如果在deny列表中,就算在allow列表中,也会被拒绝。如果allow没有配置或者为空,则允许所有访问 | |
| 63 | + #配置的格式 | |
| 64 | + #<IP> | |
| 65 | + #或者<IP>/<SUB_NET_MASK_size>其中128.242.127.1/24 | |
| 66 | + #24表示,前面24位是子网掩码,比对的时候,前面24位相同就匹配,不支持IPV6。 | |
| 67 | + #stat-view-servlet.allow= | |
| 68 | + #stat-view-servlet.deny=128.242.127.1/24,128.242.128.1 | |
| 69 | + # Spring监控配置,说明请参考Druid Github Wiki,配置_Druid和Spring关联监控配置 | |
| 70 | + #aop-patterns= # Spring监控AOP切入点,如x.y.z.service.*,配置多个英文逗号分隔 | |
| 71 | +################### mysq end ########################## | |
| 72 | + | |
| 73 | + | |
| 74 | +eureka: | |
| 75 | + instance: | |
| 76 | + hostname: localhost | |
| 77 | + lease-expiration-duration-in-seconds: 60 | |
| 78 | + lease-renewal-interval-in-seconds: 10 | |
| 79 | + client: | |
| 80 | + service-url: | |
| 81 | + defaultZone: http://121.40.109.21:8761/eureka/,http://121.40.109.21:8762/eureka/ | |
| 82 | + | |
| 83 | + | |
| 84 | + redis: | |
| 85 | + ################### redis 单机版 start ########################## | |
| 86 | + host: localhost | |
| 87 | + port: 6379 | |
| 88 | + timeout: 6000 | |
| 89 | + database: 2 | |
| 90 | + lettuce: | |
| 91 | + pool: | |
| 92 | + max-active: 10 # 连接池最大连接数(使用负值表示没有限制),如果赋值为-1,则表示不限制;如果pool已经分配了maxActive个jedis实例,则此时pool的状态为exhausted(耗尽) | |
| 93 | + max-idle: 8 # 连接池中的最大空闲连接 ,默认值也是8 | |
| 94 | + max-wait: 100 # # 等待可用连接的最大时间,单位毫秒,默认值为-1,表示永不超时。如果超过等待时间,则直接抛出JedisConnectionException | |
| 95 | + min-idle: 2 # 连接池中的最小空闲连接 ,默认值也是0 | |
| 96 | + shutdown-timeout: 100ms | |
| 0 | 97 | \ No newline at end of file | ... | ... |
cloud/autho/src/test/java/com/sincere/autho/AuthoApplicationTests.java
0 → 100644
| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | +package com.sincere.autho; | |
| 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 AuthoApplicationTests { | |
| 11 | + | |
| 12 | + @Test | |
| 13 | + public void contextLoads() { | |
| 14 | + } | |
| 15 | + | |
| 16 | +} | ... | ... |
cloud/cloud-server/.gitignore
| ... | ... | @@ -1,31 +0,0 @@ |
| 1 | -HELP.md | |
| 2 | -target/ | |
| 3 | -!.mvn/wrapper/maven-wrapper.jar | |
| 4 | -!**/src/main/** | |
| 5 | -!**/src/test/** | |
| 6 | - | |
| 7 | -### STS ### | |
| 8 | -.apt_generated | |
| 9 | -.classpath | |
| 10 | -.factorypath | |
| 11 | -.project | |
| 12 | -.settings | |
| 13 | -.springBeans | |
| 14 | -.sts4-cache | |
| 15 | - | |
| 16 | -### IntelliJ IDEA ### | |
| 17 | -.idea | |
| 18 | -*.iws | |
| 19 | -*.iml | |
| 20 | -*.ipr | |
| 21 | - | |
| 22 | -### NetBeans ### | |
| 23 | -/nbproject/private/ | |
| 24 | -/nbbuild/ | |
| 25 | -/dist/ | |
| 26 | -/nbdist/ | |
| 27 | -/.nb-gradle/ | |
| 28 | -build/ | |
| 29 | - | |
| 30 | -### VS Code ### | |
| 31 | -.vscode/ |
cloud/cloud-server/.mvn/wrapper/MavenWrapperDownloader.java
| ... | ... | @@ -1,114 +0,0 @@ |
| 1 | -/* | |
| 2 | -Licensed to the Apache Software Foundation (ASF) under one | |
| 3 | -or more contributor license agreements. See the NOTICE file | |
| 4 | -distributed with this work for additional information | |
| 5 | -regarding copyright ownership. The ASF licenses this file | |
| 6 | -to you under the Apache License, Version 2.0 (the | |
| 7 | -"License"); you may not use this file except in compliance | |
| 8 | -with the License. You may obtain a copy of the License at | |
| 9 | - | |
| 10 | - https://www.apache.org/licenses/LICENSE-2.0 | |
| 11 | - | |
| 12 | -Unless required by applicable law or agreed to in writing, | |
| 13 | -software distributed under the License is distributed on an | |
| 14 | -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| 15 | -KIND, either express or implied. See the License for the | |
| 16 | -specific language governing permissions and limitations | |
| 17 | -under the License. | |
| 18 | -*/ | |
| 19 | - | |
| 20 | -import java.io.File; | |
| 21 | -import java.io.FileInputStream; | |
| 22 | -import java.io.FileOutputStream; | |
| 23 | -import java.io.IOException; | |
| 24 | -import java.net.URL; | |
| 25 | -import java.nio.channels.Channels; | |
| 26 | -import java.nio.channels.ReadableByteChannel; | |
| 27 | -import java.util.Properties; | |
| 28 | - | |
| 29 | -public class MavenWrapperDownloader { | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. | |
| 33 | - */ | |
| 34 | - private static final String DEFAULT_DOWNLOAD_URL = | |
| 35 | - "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; | |
| 36 | - | |
| 37 | - /** | |
| 38 | - * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to | |
| 39 | - * use instead of the default one. | |
| 40 | - */ | |
| 41 | - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = | |
| 42 | - ".mvn/wrapper/maven-wrapper.properties"; | |
| 43 | - | |
| 44 | - /** | |
| 45 | - * Path where the maven-wrapper.jar will be saved to. | |
| 46 | - */ | |
| 47 | - private static final String MAVEN_WRAPPER_JAR_PATH = | |
| 48 | - ".mvn/wrapper/maven-wrapper.jar"; | |
| 49 | - | |
| 50 | - /** | |
| 51 | - * Name of the property which should be used to override the default download url for the wrapper. | |
| 52 | - */ | |
| 53 | - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; | |
| 54 | - | |
| 55 | - public static void main(String args[]) { | |
| 56 | - System.out.println("- Downloader started"); | |
| 57 | - File baseDirectory = new File(args[0]); | |
| 58 | - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); | |
| 59 | - | |
| 60 | - // If the maven-wrapper.properties exists, read it and check if it contains a custom | |
| 61 | - // wrapperUrl parameter. | |
| 62 | - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); | |
| 63 | - String url = DEFAULT_DOWNLOAD_URL; | |
| 64 | - if (mavenWrapperPropertyFile.exists()) { | |
| 65 | - FileInputStream mavenWrapperPropertyFileInputStream = null; | |
| 66 | - try { | |
| 67 | - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); | |
| 68 | - Properties mavenWrapperProperties = new Properties(); | |
| 69 | - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); | |
| 70 | - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); | |
| 71 | - } catch (IOException e) { | |
| 72 | - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); | |
| 73 | - } finally { | |
| 74 | - try { | |
| 75 | - if (mavenWrapperPropertyFileInputStream != null) { | |
| 76 | - mavenWrapperPropertyFileInputStream.close(); | |
| 77 | - } | |
| 78 | - } catch (IOException e) { | |
| 79 | - // Ignore ... | |
| 80 | - } | |
| 81 | - } | |
| 82 | - } | |
| 83 | - System.out.println("- Downloading from: : " + url); | |
| 84 | - | |
| 85 | - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); | |
| 86 | - if (!outputFile.getParentFile().exists()) { | |
| 87 | - if (!outputFile.getParentFile().mkdirs()) { | |
| 88 | - System.out.println( | |
| 89 | - "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); | |
| 90 | - } | |
| 91 | - } | |
| 92 | - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); | |
| 93 | - try { | |
| 94 | - downloadFileFromURL(url, outputFile); | |
| 95 | - System.out.println("Done"); | |
| 96 | - System.exit(0); | |
| 97 | - } catch (Throwable e) { | |
| 98 | - System.out.println("- Error downloading"); | |
| 99 | - e.printStackTrace(); | |
| 100 | - System.exit(1); | |
| 101 | - } | |
| 102 | - } | |
| 103 | - | |
| 104 | - private static void downloadFileFromURL(String urlString, File destination) throws Exception { | |
| 105 | - URL website = new URL(urlString); | |
| 106 | - ReadableByteChannel rbc; | |
| 107 | - rbc = Channels.newChannel(website.openStream()); | |
| 108 | - FileOutputStream fos = new FileOutputStream(destination); | |
| 109 | - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); | |
| 110 | - fos.close(); | |
| 111 | - rbc.close(); | |
| 112 | - } | |
| 113 | - | |
| 114 | -} |
cloud/cloud-server/.mvn/wrapper/maven-wrapper.jar
No preview for this file type
cloud/cloud-server/.mvn/wrapper/maven-wrapper.properties
| ... | ... | @@ -1 +0,0 @@ |
| 1 | -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip |
cloud/cloud-server/mvnw
| ... | ... | @@ -1,286 +0,0 @@ |
| 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 | -# https://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 "$@" |
cloud/cloud-server/mvnw.cmd
| ... | ... | @@ -1,161 +0,0 @@ |
| 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 https://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% |
cloud/cloud-server/pom.xml
| ... | ... | @@ -1,56 +0,0 @@ |
| 1 | -<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| 3 | - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| 4 | - <modelVersion>4.0.0</modelVersion> | |
| 5 | - <parent> | |
| 6 | - <groupId>org.springframework.boot</groupId> | |
| 7 | - <artifactId>spring-boot-starter-parent</artifactId> | |
| 8 | - <version>2.1.6.RELEASE</version> | |
| 9 | - <relativePath/> <!-- lookup parent from repository --> | |
| 10 | - </parent> | |
| 11 | - <groupId>com.example</groupId> | |
| 12 | - <artifactId>cloud-server</artifactId> | |
| 13 | - <version>0.0.1-SNAPSHOT</version> | |
| 14 | - <name>cloud-server</name> | |
| 15 | - <description>Demo project for Spring Boot</description> | |
| 16 | - | |
| 17 | - <properties> | |
| 18 | - <java.version>1.8</java.version> | |
| 19 | - <spring-cloud.version>Greenwich.SR2</spring-cloud.version> | |
| 20 | - </properties> | |
| 21 | - | |
| 22 | - <dependencies> | |
| 23 | - <dependency> | |
| 24 | - <groupId>org.springframework.cloud</groupId> | |
| 25 | - <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> | |
| 26 | - </dependency> | |
| 27 | - | |
| 28 | - <dependency> | |
| 29 | - <groupId>org.springframework.boot</groupId> | |
| 30 | - <artifactId>spring-boot-starter-test</artifactId> | |
| 31 | - <scope>test</scope> | |
| 32 | - </dependency> | |
| 33 | - </dependencies> | |
| 34 | - | |
| 35 | - <dependencyManagement> | |
| 36 | - <dependencies> | |
| 37 | - <dependency> | |
| 38 | - <groupId>org.springframework.cloud</groupId> | |
| 39 | - <artifactId>spring-cloud-dependencies</artifactId> | |
| 40 | - <version>${spring-cloud.version}</version> | |
| 41 | - <type>pom</type> | |
| 42 | - <scope>import</scope> | |
| 43 | - </dependency> | |
| 44 | - </dependencies> | |
| 45 | - </dependencyManagement> | |
| 46 | - | |
| 47 | - <build> | |
| 48 | - <plugins> | |
| 49 | - <plugin> | |
| 50 | - <groupId>org.springframework.boot</groupId> | |
| 51 | - <artifactId>spring-boot-maven-plugin</artifactId> | |
| 52 | - </plugin> | |
| 53 | - </plugins> | |
| 54 | - </build> | |
| 55 | - | |
| 56 | -</project> |
cloud/cloud-server/src/main/java/com/example/cloudserver/CloudServerApplication.java
| ... | ... | @@ -1,15 +0,0 @@ |
| 1 | -package com.example.cloudserver; | |
| 2 | - | |
| 3 | -import org.springframework.boot.SpringApplication; | |
| 4 | -import org.springframework.boot.autoconfigure.SpringBootApplication; | |
| 5 | -import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; | |
| 6 | - | |
| 7 | -@EnableEurekaServer | |
| 8 | -@SpringBootApplication | |
| 9 | -public class CloudServerApplication { | |
| 10 | - | |
| 11 | - public static void main(String[] args) { | |
| 12 | - SpringApplication.run(CloudServerApplication.class, args); | |
| 13 | - } | |
| 14 | - | |
| 15 | -} |
cloud/cloud-server/src/main/resources/application.yaml
cloud/cloud-server/src/test/java/com/example/cloudserver/CloudServerApplicationTests.java
| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | -package com.example.cloudserver; | |
| 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 CloudServerApplicationTests { | |
| 11 | - | |
| 12 | - @Test | |
| 13 | - public void contextLoads() { | |
| 14 | - } | |
| 15 | - | |
| 16 | -} |
| ... | ... | @@ -0,0 +1,31 @@ |
| 1 | +HELP.md | |
| 2 | +target/ | |
| 3 | +!.mvn/wrapper/maven-wrapper.jar | |
| 4 | +!**/src/main/** | |
| 5 | +!**/src/test/** | |
| 6 | + | |
| 7 | +### STS ### | |
| 8 | +.apt_generated | |
| 9 | +.classpath | |
| 10 | +.factorypath | |
| 11 | +.project | |
| 12 | +.settings | |
| 13 | +.springBeans | |
| 14 | +.sts4-cache | |
| 15 | + | |
| 16 | +### IntelliJ IDEA ### | |
| 17 | +.idea | |
| 18 | +*.iws | |
| 19 | +*.iml | |
| 20 | +*.ipr | |
| 21 | + | |
| 22 | +### NetBeans ### | |
| 23 | +/nbproject/private/ | |
| 24 | +/nbbuild/ | |
| 25 | +/dist/ | |
| 26 | +/nbdist/ | |
| 27 | +/.nb-gradle/ | |
| 28 | +build/ | |
| 29 | + | |
| 30 | +### VS Code ### | |
| 31 | +.vscode/ | ... | ... |
| ... | ... | @@ -0,0 +1,114 @@ |
| 1 | +/* | |
| 2 | +Licensed to the Apache Software Foundation (ASF) under one | |
| 3 | +or more contributor license agreements. See the NOTICE file | |
| 4 | +distributed with this work for additional information | |
| 5 | +regarding copyright ownership. The ASF licenses this file | |
| 6 | +to you under the Apache License, Version 2.0 (the | |
| 7 | +"License"); you may not use this file except in compliance | |
| 8 | +with the License. You may obtain a copy of the License at | |
| 9 | + | |
| 10 | + https://www.apache.org/licenses/LICENSE-2.0 | |
| 11 | + | |
| 12 | +Unless required by applicable law or agreed to in writing, | |
| 13 | +software distributed under the License is distributed on an | |
| 14 | +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| 15 | +KIND, either express or implied. See the License for the | |
| 16 | +specific language governing permissions and limitations | |
| 17 | +under the License. | |
| 18 | +*/ | |
| 19 | + | |
| 20 | +import java.io.File; | |
| 21 | +import java.io.FileInputStream; | |
| 22 | +import java.io.FileOutputStream; | |
| 23 | +import java.io.IOException; | |
| 24 | +import java.net.URL; | |
| 25 | +import java.nio.channels.Channels; | |
| 26 | +import java.nio.channels.ReadableByteChannel; | |
| 27 | +import java.util.Properties; | |
| 28 | + | |
| 29 | +public class MavenWrapperDownloader { | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. | |
| 33 | + */ | |
| 34 | + private static final String DEFAULT_DOWNLOAD_URL = | |
| 35 | + "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; | |
| 36 | + | |
| 37 | + /** | |
| 38 | + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to | |
| 39 | + * use instead of the default one. | |
| 40 | + */ | |
| 41 | + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = | |
| 42 | + ".mvn/wrapper/maven-wrapper.properties"; | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * Path where the maven-wrapper.jar will be saved to. | |
| 46 | + */ | |
| 47 | + private static final String MAVEN_WRAPPER_JAR_PATH = | |
| 48 | + ".mvn/wrapper/maven-wrapper.jar"; | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * Name of the property which should be used to override the default download url for the wrapper. | |
| 52 | + */ | |
| 53 | + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; | |
| 54 | + | |
| 55 | + public static void main(String args[]) { | |
| 56 | + System.out.println("- Downloader started"); | |
| 57 | + File baseDirectory = new File(args[0]); | |
| 58 | + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); | |
| 59 | + | |
| 60 | + // If the maven-wrapper.properties exists, read it and check if it contains a custom | |
| 61 | + // wrapperUrl parameter. | |
| 62 | + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); | |
| 63 | + String url = DEFAULT_DOWNLOAD_URL; | |
| 64 | + if (mavenWrapperPropertyFile.exists()) { | |
| 65 | + FileInputStream mavenWrapperPropertyFileInputStream = null; | |
| 66 | + try { | |
| 67 | + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); | |
| 68 | + Properties mavenWrapperProperties = new Properties(); | |
| 69 | + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); | |
| 70 | + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); | |
| 71 | + } catch (IOException e) { | |
| 72 | + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); | |
| 73 | + } finally { | |
| 74 | + try { | |
| 75 | + if (mavenWrapperPropertyFileInputStream != null) { | |
| 76 | + mavenWrapperPropertyFileInputStream.close(); | |
| 77 | + } | |
| 78 | + } catch (IOException e) { | |
| 79 | + // Ignore ... | |
| 80 | + } | |
| 81 | + } | |
| 82 | + } | |
| 83 | + System.out.println("- Downloading from: : " + url); | |
| 84 | + | |
| 85 | + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); | |
| 86 | + if (!outputFile.getParentFile().exists()) { | |
| 87 | + if (!outputFile.getParentFile().mkdirs()) { | |
| 88 | + System.out.println( | |
| 89 | + "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); | |
| 90 | + } | |
| 91 | + } | |
| 92 | + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); | |
| 93 | + try { | |
| 94 | + downloadFileFromURL(url, outputFile); | |
| 95 | + System.out.println("Done"); | |
| 96 | + System.exit(0); | |
| 97 | + } catch (Throwable e) { | |
| 98 | + System.out.println("- Error downloading"); | |
| 99 | + e.printStackTrace(); | |
| 100 | + System.exit(1); | |
| 101 | + } | |
| 102 | + } | |
| 103 | + | |
| 104 | + private static void downloadFileFromURL(String urlString, File destination) throws Exception { | |
| 105 | + URL website = new URL(urlString); | |
| 106 | + ReadableByteChannel rbc; | |
| 107 | + rbc = Channels.newChannel(website.openStream()); | |
| 108 | + FileOutputStream fos = new FileOutputStream(destination); | |
| 109 | + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); | |
| 110 | + fos.close(); | |
| 111 | + rbc.close(); | |
| 112 | + } | |
| 113 | + | |
| 114 | +} | ... | ... |
No preview for this file type
| ... | ... | @@ -0,0 +1 @@ |
| 1 | +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip | ... | ... |
| ... | ... | @@ -0,0 +1,286 @@ |
| 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 | +# https://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 "$@" | ... | ... |
| ... | ... | @@ -0,0 +1,161 @@ |
| 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 https://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% | ... | ... |
| ... | ... | @@ -0,0 +1,90 @@ |
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| 3 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| 4 | + <modelVersion>4.0.0</modelVersion> | |
| 5 | + <parent> | |
| 6 | + <groupId>org.springframework.boot</groupId> | |
| 7 | + <artifactId>spring-boot-starter-parent</artifactId> | |
| 8 | + <version>2.1.7.RELEASE</version> | |
| 9 | + <relativePath/> <!-- lookup parent from repository --> | |
| 10 | + </parent> | |
| 11 | + <groupId>com.sincere</groupId> | |
| 12 | + <artifactId>common</artifactId> | |
| 13 | + <version>0.0.1-SNAPSHOT</version> | |
| 14 | + <name>common</name> | |
| 15 | + <description>Demo project for Spring Boot</description> | |
| 16 | + | |
| 17 | + <properties> | |
| 18 | + <java.version>1.8</java.version> | |
| 19 | + </properties> | |
| 20 | + | |
| 21 | + <dependencies> | |
| 22 | + <dependency> | |
| 23 | + <groupId>org.springframework.boot</groupId> | |
| 24 | + <artifactId>spring-boot-starter</artifactId> | |
| 25 | + </dependency> | |
| 26 | + | |
| 27 | + <dependency> | |
| 28 | + <groupId>org.springframework.boot</groupId> | |
| 29 | + <artifactId>spring-boot-starter-test</artifactId> | |
| 30 | + <scope>test</scope> | |
| 31 | + </dependency> | |
| 32 | + | |
| 33 | + <dependency> | |
| 34 | + <groupId>org.springframework.boot</groupId> | |
| 35 | + <artifactId>spring-boot</artifactId> | |
| 36 | + </dependency> | |
| 37 | + <dependency> | |
| 38 | + <groupId>com.baomidou</groupId> | |
| 39 | + <artifactId>mybatis-plus-core</artifactId> | |
| 40 | + <version>3.0.1</version> | |
| 41 | + <scope>compile</scope> | |
| 42 | + </dependency> | |
| 43 | + | |
| 44 | + <dependency> | |
| 45 | + <groupId>com.baomidou</groupId> | |
| 46 | + <artifactId>mybatis-plus-extension</artifactId> | |
| 47 | + <version>3.0.1</version> | |
| 48 | + <scope>compile</scope> | |
| 49 | + </dependency> | |
| 50 | + | |
| 51 | + <dependency> | |
| 52 | + <groupId>org.apache.tomcat.embed</groupId> | |
| 53 | + <artifactId>tomcat-embed-core</artifactId> | |
| 54 | + </dependency> | |
| 55 | + | |
| 56 | + <dependency> | |
| 57 | + <groupId>io.jsonwebtoken</groupId> | |
| 58 | + <artifactId>jjwt</artifactId> | |
| 59 | + <version>0.9.0</version> | |
| 60 | + </dependency> | |
| 61 | + | |
| 62 | + <dependency> | |
| 63 | + <groupId>org.springframework.security</groupId> | |
| 64 | + <artifactId>spring-security-core</artifactId> | |
| 65 | + </dependency> | |
| 66 | + | |
| 67 | + <dependency> | |
| 68 | + <groupId>org.projectlombok</groupId> | |
| 69 | + <artifactId>lombok</artifactId> | |
| 70 | + </dependency> | |
| 71 | + | |
| 72 | + | |
| 73 | + <dependency> | |
| 74 | + <groupId>commons-collections</groupId> | |
| 75 | + <artifactId>commons-collections</artifactId> | |
| 76 | + <version>3.2.2</version> | |
| 77 | + </dependency> | |
| 78 | + | |
| 79 | + </dependencies> | |
| 80 | + | |
| 81 | + <build> | |
| 82 | + <plugins> | |
| 83 | + <plugin> | |
| 84 | + <groupId>org.springframework.boot</groupId> | |
| 85 | + <artifactId>spring-boot-maven-plugin</artifactId> | |
| 86 | + </plugin> | |
| 87 | + </plugins> | |
| 88 | + </build> | |
| 89 | + | |
| 90 | +</project> | ... | ... |
cloud/common/src/main/java/com/sincere/common/CommonApplication.java
0 → 100644
| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | +package com.sincere.common; | |
| 2 | + | |
| 3 | +import org.springframework.boot.SpringApplication; | |
| 4 | +import org.springframework.boot.autoconfigure.SpringBootApplication; | |
| 5 | + | |
| 6 | +@SpringBootApplication | |
| 7 | +public class CommonApplication { | |
| 8 | + | |
| 9 | + public static void main(String[] args) { | |
| 10 | + SpringApplication.run(CommonApplication.class, args); | |
| 11 | + } | |
| 12 | + | |
| 13 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/commons/CodeEnum.java
0 → 100644
| ... | ... | @@ -0,0 +1,26 @@ |
| 1 | +package com.sincere.common.commons; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * @Author: [gitgeek] | |
| 5 | + * @Date: [2018-08-02 08:50] | |
| 6 | + * @Description: [ ] | |
| 7 | + * @Version: [1.0.0] | |
| 8 | + * @Copy: [com.zzg] | |
| 9 | + */ | |
| 10 | +public enum CodeEnum { | |
| 11 | + SUCCESS(0), | |
| 12 | + ERROR(1); | |
| 13 | + | |
| 14 | + private Integer code; | |
| 15 | + CodeEnum(Integer code){ | |
| 16 | + this.code = code; | |
| 17 | + } | |
| 18 | + | |
| 19 | + public Integer getCode() { | |
| 20 | + return code; | |
| 21 | + } | |
| 22 | + | |
| 23 | + public void setCode(Integer code) { | |
| 24 | + this.code = code; | |
| 25 | + } | |
| 26 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/commons/PageResult.java
0 → 100644
| ... | ... | @@ -0,0 +1,30 @@ |
| 1 | +package com.sincere.common.commons; | |
| 2 | + | |
| 3 | +import lombok.AllArgsConstructor; | |
| 4 | +import lombok.Builder; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.NoArgsConstructor; | |
| 7 | + | |
| 8 | +import java.io.Serializable; | |
| 9 | +import java.util.List; | |
| 10 | + | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * @author 作者 owen E-mail: 624191343@qq.com | |
| 14 | + * @version 创建时间:2017年11月12日 上午22:57:51 | |
| 15 | + * 分页实体类 | |
| 16 | + * total 总数 | |
| 17 | + * code 是否成功 | |
| 18 | + * data 当前页结果集 | |
| 19 | + */ | |
| 20 | +@Data | |
| 21 | +@Builder | |
| 22 | +@NoArgsConstructor | |
| 23 | +@AllArgsConstructor | |
| 24 | +public class PageResult<T> implements Serializable { | |
| 25 | + | |
| 26 | + private static final long serialVersionUID = -275582248840137389L; | |
| 27 | + private Long count; | |
| 28 | + private int code; | |
| 29 | + private List<T> data; | |
| 30 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/commons/Result.java
0 → 100644
| ... | ... | @@ -0,0 +1,49 @@ |
| 1 | +package com.sincere.common.commons; | |
| 2 | + | |
| 3 | +import lombok.AllArgsConstructor; | |
| 4 | +import lombok.Data; | |
| 5 | +import lombok.NoArgsConstructor; | |
| 6 | + | |
| 7 | +import java.io.Serializable; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * @Author: [zhangzhiguang] | |
| 11 | + * @Date: [2018-08-01 23:39] | |
| 12 | + * @Description: [ ] | |
| 13 | + * @Version: [1.0.0] | |
| 14 | + * @Copy: [com.zzg] | |
| 15 | + */ | |
| 16 | +@Data | |
| 17 | +@NoArgsConstructor | |
| 18 | +@AllArgsConstructor | |
| 19 | +public class Result<T> implements Serializable { | |
| 20 | + | |
| 21 | + private T datas; | |
| 22 | + private Integer resp_code; | |
| 23 | + private String resp_msg; | |
| 24 | + | |
| 25 | + public static <T> Result<T> succeed(String msg) { | |
| 26 | + return succeedWith(null, CodeEnum.SUCCESS.getCode(),msg); | |
| 27 | + } | |
| 28 | + | |
| 29 | + public static <T> Result<T> succeed(T model, String msg) { | |
| 30 | + return succeedWith(model, CodeEnum.SUCCESS.getCode(),msg); | |
| 31 | + } | |
| 32 | + | |
| 33 | + public static <T> Result<T> succeedWith(T datas, Integer code,String msg) { | |
| 34 | + return new Result<T>(datas, code, msg); | |
| 35 | + } | |
| 36 | + | |
| 37 | + public static <T> Result<T> failed(String msg) { | |
| 38 | + return failedWith(null, CodeEnum.ERROR.getCode(), msg); | |
| 39 | + } | |
| 40 | + | |
| 41 | + public static <T> Result<T> failed(T model,String msg) { | |
| 42 | + return failedWith(model, CodeEnum.ERROR.getCode(), msg); | |
| 43 | + } | |
| 44 | + | |
| 45 | + public static <T> Result<T> failedWith(T datas, Integer code, String msg) { | |
| 46 | + return new Result<T>( datas, code, msg); | |
| 47 | + } | |
| 48 | + | |
| 49 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/config/DataSourceHolder.java
0 → 100644
| ... | ... | @@ -0,0 +1,25 @@ |
| 1 | +package com.sincere.common.config; | |
| 2 | + | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * 用于数据源切换 | |
| 6 | + * | |
| 7 | + */ | |
| 8 | +public class DataSourceHolder { | |
| 9 | + | |
| 10 | + private static final ThreadLocal<DataSourceKey> dataSourceKey = new ThreadLocal<>(); | |
| 11 | + | |
| 12 | + public static DataSourceKey getDataSourceKey() { | |
| 13 | + return dataSourceKey.get(); | |
| 14 | + } | |
| 15 | + | |
| 16 | + public static void setDataSourceKey(DataSourceKey type) { | |
| 17 | + dataSourceKey.set(type); | |
| 18 | + } | |
| 19 | + | |
| 20 | + public static void clearDataSourceKey() { | |
| 21 | + dataSourceKey.remove(); | |
| 22 | + } | |
| 23 | + | |
| 24 | + | |
| 25 | +} | |
| 0 | 26 | \ No newline at end of file | ... | ... |
cloud/common/src/main/java/com/sincere/common/config/DataSourceKey.java
0 → 100644
cloud/common/src/main/java/com/sincere/common/constants/CommonConstants.java
0 → 100644
| ... | ... | @@ -0,0 +1,21 @@ |
| 1 | +package com.sincere.common.constants; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * @author: yukong | |
| 5 | + * @date: 2018/10/17 15:18 | |
| 6 | + * @description: | |
| 7 | + */ | |
| 8 | +public interface CommonConstants { | |
| 9 | + | |
| 10 | + /** | |
| 11 | + * 树的根节点值 | |
| 12 | + */ | |
| 13 | + Integer TREE_ROOT = -1; | |
| 14 | + | |
| 15 | + String PANDA_REDIS_LIST_LEY = "panda_client_id_to_access:cloud"; | |
| 16 | + | |
| 17 | + String DEFAULT_PARAMTER_KEY = "parameter"; | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/constants/MqQueueNameConstant.java
0 → 100644
| ... | ... | @@ -0,0 +1,21 @@ |
| 1 | +package com.sincere.common.constants; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * @author: yukong | |
| 5 | + * @date: 2018/11/14 15:42 | |
| 6 | + */ | |
| 7 | +public interface MqQueueNameConstant { | |
| 8 | + | |
| 9 | + /** | |
| 10 | + * 系统日志队列 | |
| 11 | + */ | |
| 12 | + String SYS_LOG_QUEUE= "sys_log_queue"; | |
| 13 | + /** | |
| 14 | + * 短信验证码队列 | |
| 15 | + */ | |
| 16 | + String MOBILE_CODE_QUEUE= "mobile_code_queue"; | |
| 17 | + /** | |
| 18 | + * 邮件队列 | |
| 19 | + */ | |
| 20 | + String MAIL_CODE_QUEUE= "mail_code_queue"; | |
| 21 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/constants/PandaServiceNameConstants.java
0 → 100644
| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | +package com.sincere.common.constants; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * @author: yukong | |
| 5 | + * @date: 2018/11/14 15:52 | |
| 6 | + */ | |
| 7 | +public interface PandaServiceNameConstants { | |
| 8 | + | |
| 9 | + String PANDA_AUTH = "PANDA_AUTH"; | |
| 10 | + String PANDA_COMMON = "PANDA_COMMON"; | |
| 11 | + String PANDA_CONFIG_SERVER = "PANDA_CONFIG_SERVER"; | |
| 12 | + String PANDA_GATEWAY = "PANDA_GATEWAY"; | |
| 13 | + String PANDA_SERVER = "PANDA_SERVER"; | |
| 14 | + String PANDA_USER_SERVICE = "PANDA_USER_SERVICE"; | |
| 15 | + String PANDA_GEN_SERVICE = "PANDA_GEN_SERVICE"; | |
| 16 | + | |
| 17 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/constants/SecurityConstants.java
0 → 100644
| ... | ... | @@ -0,0 +1,61 @@ |
| 1 | +package com.sincere.common.constants; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * @author: yukong | |
| 5 | + * @date: 2018/10/9 15:10 | |
| 6 | + * @description: 安全配置常量 | |
| 7 | + */ | |
| 8 | +public interface SecurityConstants { | |
| 9 | + | |
| 10 | + /** | |
| 11 | + * token的header key | |
| 12 | + */ | |
| 13 | + String TOKEN_HEADER = "Authorization"; | |
| 14 | + | |
| 15 | + String CLOUD = "panda"; | |
| 16 | + | |
| 17 | + String CLOUD_PREFIX = "panda_"; | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * jwt 加密key | |
| 21 | + */ | |
| 22 | + String SIGN_KEY = "PANDA"; | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * sys_oauth_client_details 字段 | |
| 26 | + */ | |
| 27 | + String CLIENT_FIELDS = "client_id, client_secret, resources_ids, scope, authorized_grant_types," | |
| 28 | + + "web_server_redirect_uri, authorities, access_token_validity," | |
| 29 | + + "refresh_token_validity, addition_information, autoapprove"; | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * jdbcClientDetailsService查询sql | |
| 33 | + */ | |
| 34 | + String BASE_FIND_STATEMENT = "select " + CLIENT_FIELDS + " from sys_oauth_client_details"; | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * 默认查询语句 | |
| 38 | + */ | |
| 39 | + String DEFAULT_FIND_STATEMENT = BASE_FIND_STATEMENT + " order by client_id"; | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * 根据client_id查询 | |
| 43 | + */ | |
| 44 | + String DEFAULT_FIND_STATEMENT_BY_CLIENT_ID = BASE_FIND_STATEMENT + " where client_id = ?"; | |
| 45 | + | |
| 46 | + | |
| 47 | + String SPRING_SECURITY_MOBILE_KEY = "mobile"; | |
| 48 | + | |
| 49 | + String SPRING_SECURITY_CODE_KEY = "code"; | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * 手机验证码登录的地址 | |
| 53 | + */ | |
| 54 | + String SPRING_SECURITY_MOBILE_TOKEN_URL = "/mobile/token"; | |
| 55 | + | |
| 56 | + | |
| 57 | + String REDIS_CODE_PREFIX = "panda_code:"; | |
| 58 | + | |
| 59 | + Integer REDIS_CODE_EXPIRE = 60; | |
| 60 | + | |
| 61 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/constants/UserConstants.java
0 → 100644
| ... | ... | @@ -0,0 +1,26 @@ |
| 1 | +package com.sincere.common.constants; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * @author: yukong | |
| 5 | + * @date: 2018/10/17 09:24 | |
| 6 | + * @description: | |
| 7 | + */ | |
| 8 | +public interface UserConstants { | |
| 9 | + | |
| 10 | + /** | |
| 11 | + * jwt中 用户id的key | |
| 12 | + */ | |
| 13 | + String USER_ID = "userId"; | |
| 14 | + | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * jwt中 用户userName的key | |
| 18 | + */ | |
| 19 | + String USER_NAME = "userName"; | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * jwt中 角色集合的key | |
| 23 | + */ | |
| 24 | + String AUTHORITIES = "authorities"; | |
| 25 | + | |
| 26 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/entity/SysUser.java
0 → 100644
| ... | ... | @@ -0,0 +1,99 @@ |
| 1 | +package com.sincere.common.entity; | |
| 2 | + | |
| 3 | + | |
| 4 | +import lombok.Data; | |
| 5 | +import lombok.experimental.Accessors; | |
| 6 | + | |
| 7 | +import java.time.LocalDateTime; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * <p> | |
| 11 | + * 用户表 | |
| 12 | + * </p> | |
| 13 | + * | |
| 14 | + * @author yukong | |
| 15 | + * @since 2018-10-08 | |
| 16 | + */ | |
| 17 | +@Data | |
| 18 | +@Accessors(chain = true) | |
| 19 | +public class SysUser { | |
| 20 | + | |
| 21 | + private static final long serialVersionUID = 1L; | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * 主键ID | |
| 25 | + */ | |
| 26 | + private Integer userId; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 用户名 | |
| 30 | + */ | |
| 31 | + private String username; | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * 密码 | |
| 35 | + */ | |
| 36 | + private String password; | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * 邮箱 | |
| 40 | + */ | |
| 41 | + private String email; | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * 手机号码 | |
| 45 | + */ | |
| 46 | + private String mobile; | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * qq号码 | |
| 50 | + */ | |
| 51 | + private String qq; | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * 微信号码 | |
| 55 | + */ | |
| 56 | + private String wechat; | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * 微博url | |
| 60 | + */ | |
| 61 | + private String weibo; | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * 头像url | |
| 65 | + */ | |
| 66 | + private String avatar; | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * qq openid | |
| 70 | + */ | |
| 71 | + private String qqOpenid; | |
| 72 | + | |
| 73 | + /** | |
| 74 | + * 微信openid | |
| 75 | + */ | |
| 76 | + private String wechatOpenid; | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * 微博openid | |
| 80 | + */ | |
| 81 | + private String weiboOpenid; | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * 创建时间 | |
| 85 | + */ | |
| 86 | + private LocalDateTime createTime; | |
| 87 | + | |
| 88 | + /** | |
| 89 | + * 更新时间 | |
| 90 | + */ | |
| 91 | + private LocalDateTime modifyTime; | |
| 92 | + | |
| 93 | + /** | |
| 94 | + * 是否删除 0-未删除 1-删除 | |
| 95 | + */ | |
| 96 | + private String delFlag; | |
| 97 | + | |
| 98 | + | |
| 99 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/enums/ApiErrorCodeEnum.java
0 → 100644
| ... | ... | @@ -0,0 +1,57 @@ |
| 1 | +package com.sincere.common.enums; | |
| 2 | + | |
| 3 | + | |
| 4 | +import com.baomidou.mybatisplus.extension.api.IErrorCode; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * @author yukong | |
| 8 | + * @date 2019-04-20 18:54 | |
| 9 | + */ | |
| 10 | +public enum ApiErrorCodeEnum implements IErrorCode { | |
| 11 | + /** | |
| 12 | + * 失败 | |
| 13 | + */ | |
| 14 | + FAILED(-1, "失败"), | |
| 15 | + /** | |
| 16 | + * 成功 | |
| 17 | + */ | |
| 18 | + SUCCESS(0, "成功"), | |
| 19 | + | |
| 20 | + /** | |
| 21 | + * 认证失败 | |
| 22 | + */ | |
| 23 | + AUTHORIZED_FAILED(-2, "用户名或密码错误"); | |
| 24 | + | |
| 25 | + private final long code; | |
| 26 | + private final String msg; | |
| 27 | + | |
| 28 | + ApiErrorCodeEnum(final long code, final String msg) { | |
| 29 | + this.code = code; | |
| 30 | + this.msg = msg; | |
| 31 | + } | |
| 32 | + | |
| 33 | + public static ApiErrorCodeEnum fromCode(long code) { | |
| 34 | + ApiErrorCodeEnum[] ecs = ApiErrorCodeEnum.values(); | |
| 35 | + for (ApiErrorCodeEnum ec : ecs) { | |
| 36 | + if (ec.getCode() == code) { | |
| 37 | + return ec; | |
| 38 | + } | |
| 39 | + } | |
| 40 | + return SUCCESS; | |
| 41 | + } | |
| 42 | + | |
| 43 | + @Override | |
| 44 | + public long getCode() { | |
| 45 | + return code; | |
| 46 | + } | |
| 47 | + | |
| 48 | + @Override | |
| 49 | + public String getMsg() { | |
| 50 | + return msg; | |
| 51 | + } | |
| 52 | + | |
| 53 | + @Override | |
| 54 | + public String toString() { | |
| 55 | + return String.format(" ErrorCode:{code=%s, msg=%s} ", code, msg); | |
| 56 | + } | |
| 57 | +} | |
| 0 | 58 | \ No newline at end of file | ... | ... |
cloud/common/src/main/java/com/sincere/common/enums/DataStatusEnum.java
0 → 100644
| ... | ... | @@ -0,0 +1,30 @@ |
| 1 | +package com.sincere.common.enums; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * @author: yukong | |
| 5 | + * @date: 2018/10/9 14:35 | |
| 6 | + * @description: 数据状态枚举 | |
| 7 | + */ | |
| 8 | +public enum DataStatusEnum { | |
| 9 | + | |
| 10 | + NORMAL("0", "正常"), | |
| 11 | + LOCK("1","删除"); | |
| 12 | + | |
| 13 | + | |
| 14 | + private String code; | |
| 15 | + | |
| 16 | + private String message; | |
| 17 | + | |
| 18 | + DataStatusEnum(String code, String message) { | |
| 19 | + this.code = code; | |
| 20 | + this.message = message; | |
| 21 | + } | |
| 22 | + | |
| 23 | + public String getCode() { | |
| 24 | + return code; | |
| 25 | + } | |
| 26 | + | |
| 27 | + public String getMessage() { | |
| 28 | + return message; | |
| 29 | + } | |
| 30 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/enums/JobDataStatusEnum.java
0 → 100644
| ... | ... | @@ -0,0 +1,37 @@ |
| 1 | +package com.sincere.common.enums; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * @author yukong | |
| 5 | + * @date 2018/10/9 14:35 | |
| 6 | + * @description job任务状态枚举 | |
| 7 | + */ | |
| 8 | +public enum JobDataStatusEnum { | |
| 9 | + | |
| 10 | + /** | |
| 11 | + * 运行中 | |
| 12 | + */ | |
| 13 | + UP(0, "运行"), | |
| 14 | + | |
| 15 | + /** | |
| 16 | + * 停止 | |
| 17 | + */ | |
| 18 | + STOP(1,"停止"); | |
| 19 | + | |
| 20 | + | |
| 21 | + private Integer code; | |
| 22 | + | |
| 23 | + private String message; | |
| 24 | + | |
| 25 | + JobDataStatusEnum(Integer code, String message) { | |
| 26 | + this.code = code; | |
| 27 | + this.message = message; | |
| 28 | + } | |
| 29 | + | |
| 30 | + public Integer getCode() { | |
| 31 | + return code; | |
| 32 | + } | |
| 33 | + | |
| 34 | + public String getMessage() { | |
| 35 | + return message; | |
| 36 | + } | |
| 37 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/enums/OperationStatusEnum.java
0 → 100644
| ... | ... | @@ -0,0 +1,30 @@ |
| 1 | +package com.sincere.common.enums; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * @author: yukong | |
| 5 | + * @date: 2018/10/9 14:35 | |
| 6 | + * @description: 用户状态枚举 | |
| 7 | + */ | |
| 8 | +public enum OperationStatusEnum { | |
| 9 | + | |
| 10 | + SUCCESS("0", "成功"), | |
| 11 | + FAIL("1","失败"); | |
| 12 | + | |
| 13 | + | |
| 14 | + private String code; | |
| 15 | + | |
| 16 | + private String message; | |
| 17 | + | |
| 18 | + OperationStatusEnum(String code, String message) { | |
| 19 | + this.code = code; | |
| 20 | + this.message = message; | |
| 21 | + } | |
| 22 | + | |
| 23 | + public String getCode() { | |
| 24 | + return code; | |
| 25 | + } | |
| 26 | + | |
| 27 | + public String getMessage() { | |
| 28 | + return message; | |
| 29 | + } | |
| 30 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/enums/PasswordEncoderEnum.java
0 → 100644
| ... | ... | @@ -0,0 +1,27 @@ |
| 1 | +package com.sincere.common.enums; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * @author yukong | |
| 5 | + * @date 2019-04-23 14:15 | |
| 6 | + */ | |
| 7 | +public enum PasswordEncoderEnum { | |
| 8 | + | |
| 9 | + /** | |
| 10 | + * bcrypt加密 | |
| 11 | + */ | |
| 12 | + BCRYPT("{bcrypt}"), | |
| 13 | + /** | |
| 14 | + * 明文 | |
| 15 | + */ | |
| 16 | + NOOP("{noop}"); | |
| 17 | + | |
| 18 | + private String value; | |
| 19 | + | |
| 20 | + private PasswordEncoderEnum(String value){ | |
| 21 | + this.value = value; | |
| 22 | + } | |
| 23 | + | |
| 24 | + public String getValue() { | |
| 25 | + return value; | |
| 26 | + } | |
| 27 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/enums/ResourceTypeEnum.java
0 → 100644
| ... | ... | @@ -0,0 +1,29 @@ |
| 1 | +package com.sincere.common.enums; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * @author: yukong | |
| 5 | + * @date: 2018/10/17 16:03 | |
| 6 | + * @description: 资源类型枚举 | |
| 7 | + */ | |
| 8 | +public enum ResourceTypeEnum { | |
| 9 | + MENU("0", "菜单"), | |
| 10 | + BUTTON("1","按钮"); | |
| 11 | + | |
| 12 | + | |
| 13 | + private String code; | |
| 14 | + | |
| 15 | + private String message; | |
| 16 | + | |
| 17 | + ResourceTypeEnum(String code, String message) { | |
| 18 | + this.code = code; | |
| 19 | + this.message = message; | |
| 20 | + } | |
| 21 | + | |
| 22 | + public String getCode() { | |
| 23 | + return code; | |
| 24 | + } | |
| 25 | + | |
| 26 | + public String getMessage() { | |
| 27 | + return message; | |
| 28 | + } | |
| 29 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/enums/ResponseCodeEnum.java
0 → 100644
| ... | ... | @@ -0,0 +1,36 @@ |
| 1 | +package com.sincere.common.enums; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * @author: yukong | |
| 5 | + * @date: 2018/10/12 10:51 | |
| 6 | + * @description: 响应信息code枚举 | |
| 7 | + */ | |
| 8 | +public enum ResponseCodeEnum { | |
| 9 | + | |
| 10 | + SUCCESS(0, "success"), | |
| 11 | + | |
| 12 | + NOT_LOGIN(-1,"need login"), | |
| 13 | + | |
| 14 | + FAIL(-1,"fail"), | |
| 15 | + | |
| 16 | + PERMISSION_DEFINED(2,"permission defined"); | |
| 17 | + | |
| 18 | + | |
| 19 | + private Integer code; | |
| 20 | + | |
| 21 | + private String message; | |
| 22 | + | |
| 23 | + ResponseCodeEnum(Integer code, String message) { | |
| 24 | + this.code = code; | |
| 25 | + this.message = message; | |
| 26 | + } | |
| 27 | + | |
| 28 | + public Integer getCode() { | |
| 29 | + return code; | |
| 30 | + } | |
| 31 | + | |
| 32 | + public String getMessage() { | |
| 33 | + return message; | |
| 34 | + } | |
| 35 | + | |
| 36 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/enums/SmsMessageChannnelEnum.java
0 → 100644
| ... | ... | @@ -0,0 +1,27 @@ |
| 1 | +package com.sincere.common.enums; | |
| 2 | + | |
| 3 | +import lombok.Getter; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * @author: yukong | |
| 7 | + * @date: 2018/12/3 10:44 | |
| 8 | + */ | |
| 9 | + | |
| 10 | +public enum SmsMessageChannnelEnum { | |
| 11 | + | |
| 12 | + /** | |
| 13 | + * 腾讯云 | |
| 14 | + */ | |
| 15 | + TENCENT_CLOUD("smsTencentCloudMessageHandler", "腾讯云"); | |
| 16 | + | |
| 17 | + @Getter | |
| 18 | + String code; | |
| 19 | + | |
| 20 | + @Getter | |
| 21 | + String desc; | |
| 22 | + | |
| 23 | + private SmsMessageChannnelEnum(String code, String desc) { | |
| 24 | + this.code = code; | |
| 25 | + this.desc = desc; | |
| 26 | + } | |
| 27 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/enums/SmsTemplateEnum.java
0 → 100644
| ... | ... | @@ -0,0 +1,26 @@ |
| 1 | +package com.sincere.common.enums; | |
| 2 | + | |
| 3 | +import lombok.Getter; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * @author: yukong | |
| 7 | + * @date: 2018/12/14 14:53 | |
| 8 | + */ | |
| 9 | +public enum SmsTemplateEnum { | |
| 10 | + | |
| 11 | + /** | |
| 12 | + * 腾讯云 | |
| 13 | + */ | |
| 14 | + LOGIN_CODE("程序咖啡厅", "238684"); | |
| 15 | + | |
| 16 | + @Getter | |
| 17 | + String signName; | |
| 18 | + | |
| 19 | + @Getter | |
| 20 | + String tempalte; | |
| 21 | + | |
| 22 | + private SmsTemplateEnum(String signName, String tempalte) { | |
| 23 | + this.signName = signName; | |
| 24 | + this.tempalte = tempalte; | |
| 25 | + } | |
| 26 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/enums/SysLogTypeEnum.java
0 → 100644
| ... | ... | @@ -0,0 +1,29 @@ |
| 1 | +package com.sincere.common.enums; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * @author: yukong | |
| 5 | + * @date: 2018/10/17 16:03 | |
| 6 | + * @description: 资源类型枚举 | |
| 7 | + */ | |
| 8 | +public enum SysLogTypeEnum { | |
| 9 | + LOGIN("0", "登录日志"), | |
| 10 | + OPERATOR("1","操作日志"); | |
| 11 | + | |
| 12 | + | |
| 13 | + private String code; | |
| 14 | + | |
| 15 | + private String message; | |
| 16 | + | |
| 17 | + SysLogTypeEnum(String code, String message) { | |
| 18 | + this.code = code; | |
| 19 | + this.message = message; | |
| 20 | + } | |
| 21 | + | |
| 22 | + public String getCode() { | |
| 23 | + return code; | |
| 24 | + } | |
| 25 | + | |
| 26 | + public String getMessage() { | |
| 27 | + return message; | |
| 28 | + } | |
| 29 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/enums/UserStatusEnum.java
0 → 100644
| ... | ... | @@ -0,0 +1,37 @@ |
| 1 | +package com.sincere.common.enums; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * @author: yukong | |
| 5 | + * @date: 2018/10/9 14:35 | |
| 6 | + * @description: 用户状态枚举 | |
| 7 | + */ | |
| 8 | +public enum UserStatusEnum { | |
| 9 | + | |
| 10 | + /** | |
| 11 | + * 正常 | |
| 12 | + */ | |
| 13 | + NORMAL("0", "正常"), | |
| 14 | + | |
| 15 | + /** | |
| 16 | + * 锁定 | |
| 17 | + */ | |
| 18 | + LOCK("1","锁定"); | |
| 19 | + | |
| 20 | + | |
| 21 | + private String code; | |
| 22 | + | |
| 23 | + private String message; | |
| 24 | + | |
| 25 | + UserStatusEnum(String code, String message) { | |
| 26 | + this.code = code; | |
| 27 | + this.message = message; | |
| 28 | + } | |
| 29 | + | |
| 30 | + public String getCode() { | |
| 31 | + return code; | |
| 32 | + } | |
| 33 | + | |
| 34 | + public String getMessage() { | |
| 35 | + return message; | |
| 36 | + } | |
| 37 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/model/log/SysLog.java
0 → 100644
| ... | ... | @@ -0,0 +1,37 @@ |
| 1 | +package com.sincere.common.model.log; | |
| 2 | + | |
| 3 | +import lombok.AllArgsConstructor; | |
| 4 | +import lombok.Builder; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.NoArgsConstructor; | |
| 7 | + | |
| 8 | +import java.io.Serializable; | |
| 9 | +import java.util.Date; | |
| 10 | + | |
| 11 | + | |
| 12 | +/** | |
| 13 | +* @author 作者 owen E-mail: 624191343@qq.com | |
| 14 | +* @version 创建时间:2017年11月12日 上午22:57:51 | |
| 15 | +* 日志实体 | |
| 16 | + */ | |
| 17 | +@Builder | |
| 18 | +@Data | |
| 19 | +@NoArgsConstructor | |
| 20 | +@AllArgsConstructor | |
| 21 | +public class SysLog implements Serializable { | |
| 22 | + | |
| 23 | + private static final long serialVersionUID = -5398795297842978376L; | |
| 24 | + | |
| 25 | + private Long id; | |
| 26 | +// 用户名 | |
| 27 | + private String username; | |
| 28 | +// 归属模块 | |
| 29 | + private String module; | |
| 30 | +// 执行方法的参数值 | |
| 31 | + private String params; | |
| 32 | + private String remark; | |
| 33 | +// 是否执行成功 | |
| 34 | + private Boolean flag; | |
| 35 | + | |
| 36 | + private Date createTime; | |
| 37 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/model/system/LoginAppUser.java
0 → 100644
| ... | ... | @@ -0,0 +1,93 @@ |
| 1 | +package com.sincere.common.model.system; | |
| 2 | + | |
| 3 | +import com.fasterxml.jackson.annotation.JsonIgnore; | |
| 4 | +import lombok.Getter; | |
| 5 | +import lombok.Setter; | |
| 6 | +import org.springframework.security.core.GrantedAuthority; | |
| 7 | +import org.springframework.security.core.authority.SimpleGrantedAuthority; | |
| 8 | +import org.springframework.security.core.userdetails.UserDetails; | |
| 9 | +import org.springframework.util.CollectionUtils; | |
| 10 | + | |
| 11 | +import java.io.Serializable; | |
| 12 | +import java.util.Collection; | |
| 13 | +import java.util.HashSet; | |
| 14 | +import java.util.Set; | |
| 15 | + | |
| 16 | +/** | |
| 17 | + * 用户实体绑定spring security | |
| 18 | + */ | |
| 19 | +@Getter | |
| 20 | +@Setter | |
| 21 | +public class LoginAppUser extends SysUser implements UserDetails { | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * | |
| 25 | + */ | |
| 26 | + private static final long serialVersionUID = -3685249101751401211L; | |
| 27 | + | |
| 28 | + private Set<SysRole> sysRoles; | |
| 29 | + | |
| 30 | + private Set<String> permissions; | |
| 31 | + | |
| 32 | + /*** | |
| 33 | + * 权限重写 | |
| 34 | + */ | |
| 35 | + @JsonIgnore | |
| 36 | + @Override | |
| 37 | + public Collection<? extends GrantedAuthority> getAuthorities() { | |
| 38 | + Collection<GrantedAuthority> collection = new HashSet<>(); | |
| 39 | + if (!CollectionUtils.isEmpty(sysRoles)) { | |
| 40 | + sysRoles.parallelStream().forEach(role -> { | |
| 41 | + if (role.getCode().startsWith("ROLE_")) { | |
| 42 | + collection.add(new SimpleGrantedAuthority(role.getCode())); | |
| 43 | + } else { | |
| 44 | + collection.add(new SimpleGrantedAuthority("ROLE_" + role.getCode())); | |
| 45 | + } | |
| 46 | + }); | |
| 47 | + } | |
| 48 | + | |
| 49 | + if (!CollectionUtils.isEmpty(permissions)) { | |
| 50 | + permissions.parallelStream().forEach(per -> { | |
| 51 | + collection.add(new SimpleGrantedAuthority(per)); | |
| 52 | + }); | |
| 53 | + } | |
| 54 | + | |
| 55 | + return collection; | |
| 56 | + } | |
| 57 | + | |
| 58 | + | |
| 59 | + @JsonIgnore | |
| 60 | + public Collection<? extends GrantedAuthority> putAll( Collection<GrantedAuthority> collections) { | |
| 61 | + Collection<GrantedAuthority> collection = new HashSet<>(); | |
| 62 | + | |
| 63 | + collection.addAll(collections) ; | |
| 64 | + | |
| 65 | + return collection; | |
| 66 | + } | |
| 67 | + | |
| 68 | + | |
| 69 | + @Override | |
| 70 | + public boolean isAccountNonExpired() { | |
| 71 | + return true; | |
| 72 | + } | |
| 73 | + | |
| 74 | + @Override | |
| 75 | + public boolean isAccountNonLocked() { | |
| 76 | + return true; | |
| 77 | + } | |
| 78 | + | |
| 79 | + @Override | |
| 80 | + public boolean isCredentialsNonExpired() { | |
| 81 | + return true; | |
| 82 | + } | |
| 83 | + | |
| 84 | + @Override | |
| 85 | + public boolean isEnabled() { | |
| 86 | + return getEnabled(); | |
| 87 | + } | |
| 88 | + | |
| 89 | + @Override | |
| 90 | + protected Serializable pkVal() { | |
| 91 | + return null; | |
| 92 | + } | |
| 93 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/model/system/SysMenu.java
0 → 100644
| ... | ... | @@ -0,0 +1,37 @@ |
| 1 | +package com.sincere.common.model.system; | |
| 2 | + | |
| 3 | +import com.fasterxml.jackson.databind.annotation.JsonSerialize; | |
| 4 | +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | |
| 5 | +import lombok.Data; | |
| 6 | + | |
| 7 | +import java.io.Serializable; | |
| 8 | +import java.util.Date; | |
| 9 | +import java.util.List; | |
| 10 | +import java.util.Set; | |
| 11 | + | |
| 12 | +@Data | |
| 13 | +public class SysMenu implements Serializable { | |
| 14 | + | |
| 15 | + private static final long serialVersionUID = 749360940290141180L; | |
| 16 | + @JsonSerialize(using= ToStringSerializer.class) | |
| 17 | + private Long id; | |
| 18 | + private Long parentId; | |
| 19 | + private String name; | |
| 20 | + private String css; | |
| 21 | + private String url; | |
| 22 | + private String path; | |
| 23 | + private Integer sort; | |
| 24 | + private Date createTime; | |
| 25 | + private Date updateTime; | |
| 26 | + private Integer isMenu; | |
| 27 | + private Boolean hidden; | |
| 28 | + | |
| 29 | + | |
| 30 | + private List<SysMenu> subMenus; | |
| 31 | + | |
| 32 | + private Long roleId; | |
| 33 | + private Set<Long> menuIds; | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/model/system/SysPermission.java
0 → 100644
| ... | ... | @@ -0,0 +1,47 @@ |
| 1 | +package com.sincere.common.model.system; | |
| 2 | + | |
| 3 | +import com.baomidou.mybatisplus.annotation.IdType; | |
| 4 | +import com.baomidou.mybatisplus.annotation.TableField; | |
| 5 | +import com.baomidou.mybatisplus.annotation.TableId; | |
| 6 | +import com.baomidou.mybatisplus.annotation.TableName; | |
| 7 | +import com.baomidou.mybatisplus.extension.activerecord.Model; | |
| 8 | +import com.fasterxml.jackson.databind.annotation.JsonSerialize; | |
| 9 | +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | |
| 10 | +import lombok.Data; | |
| 11 | + | |
| 12 | +import java.io.Serializable; | |
| 13 | +import java.util.Date; | |
| 14 | +import java.util.Set; | |
| 15 | + | |
| 16 | + | |
| 17 | +/** | |
| 18 | + * @author 作者 owen E-mail: 624191343@qq.com | |
| 19 | + * @version 创建时间:2017年11月12日 上午22:57:51 | |
| 20 | + * 权限标识 | |
| 21 | + */ | |
| 22 | +@Data | |
| 23 | +@TableName("sys_permission") | |
| 24 | +public class SysPermission extends Model<SysPermission> implements Serializable { | |
| 25 | + /** | |
| 26 | + * | |
| 27 | + */ | |
| 28 | + private static final long serialVersionUID = 1389727646460449239L; | |
| 29 | + @TableId(value="id",type= IdType.ID_WORKER) //雪花算法 id生成策略 | |
| 30 | + @JsonSerialize(using= ToStringSerializer.class) | |
| 31 | + private Long id; | |
| 32 | + private String permission; | |
| 33 | + private String name; | |
| 34 | + @TableField(value="createTime") | |
| 35 | + private Date createTime; | |
| 36 | + @TableField(value="updateTime") | |
| 37 | + private Date updateTime; | |
| 38 | + @TableField(exist=false) | |
| 39 | + private Long roleId; | |
| 40 | + @TableField(exist=false) | |
| 41 | + private Set<Long> authIds; | |
| 42 | + | |
| 43 | + @Override | |
| 44 | + protected Serializable pkVal() { | |
| 45 | + return null; | |
| 46 | + } | |
| 47 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/model/system/SysRole.java
0 → 100644
| ... | ... | @@ -0,0 +1,29 @@ |
| 1 | +package com.sincere.common.model.system; | |
| 2 | + | |
| 3 | +import com.fasterxml.jackson.databind.annotation.JsonSerialize; | |
| 4 | +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | |
| 5 | +import lombok.Data; | |
| 6 | + | |
| 7 | +import java.io.Serializable; | |
| 8 | +import java.util.Date; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * @author 作者 owen E-mail: 624191343@qq.com | |
| 12 | + * @version 创建时间:2017年11月12日 上午22:57:51 | |
| 13 | + * 角色 | |
| 14 | + */ | |
| 15 | +@Data | |
| 16 | +public class SysRole implements Serializable { | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * | |
| 20 | + */ | |
| 21 | + private static final long serialVersionUID = 4497149010220586111L; | |
| 22 | + @JsonSerialize(using= ToStringSerializer.class) | |
| 23 | + private Long id; | |
| 24 | + private String code; | |
| 25 | + private String name; | |
| 26 | + private Date createTime; | |
| 27 | + private Date updateTime; | |
| 28 | + private Long userId; | |
| 29 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/model/system/SysUser.java
0 → 100644
| ... | ... | @@ -0,0 +1,60 @@ |
| 1 | +package com.sincere.common.model.system; | |
| 2 | + | |
| 3 | +import com.baomidou.mybatisplus.annotation.IdType; | |
| 4 | +import com.baomidou.mybatisplus.annotation.TableField; | |
| 5 | +import com.baomidou.mybatisplus.annotation.TableId; | |
| 6 | +import com.baomidou.mybatisplus.annotation.TableName; | |
| 7 | +import com.baomidou.mybatisplus.extension.activerecord.Model; | |
| 8 | +import com.fasterxml.jackson.databind.annotation.JsonSerialize; | |
| 9 | +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | |
| 10 | +import lombok.Data; | |
| 11 | + | |
| 12 | +import java.io.Serializable; | |
| 13 | +import java.util.Date; | |
| 14 | +import java.util.List; | |
| 15 | + | |
| 16 | +/** | |
| 17 | + * @author 作者 owen E-mail: 624191343@qq.com | |
| 18 | + * @version 创建时间:2017年11月12日 上午22:57:51 | |
| 19 | + * 用户实体 | |
| 20 | + */ | |
| 21 | +@Data | |
| 22 | +@TableName("sys_user") | |
| 23 | +public class SysUser extends Model<SysUser> implements Serializable { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * | |
| 27 | + */ | |
| 28 | + private static final long serialVersionUID = -5886012896705137070L; | |
| 29 | + @TableId(value="id",type= IdType.ID_WORKER) //雪花算法 id生成策略 | |
| 30 | + @JsonSerialize(using= ToStringSerializer.class) | |
| 31 | + private Long id; | |
| 32 | + private String username; | |
| 33 | + private String password; | |
| 34 | + private String nickname; | |
| 35 | + private String headImgUrl; | |
| 36 | + private String phone; | |
| 37 | + private Integer sex; | |
| 38 | + private Boolean enabled; | |
| 39 | + private String type; | |
| 40 | + @TableField(value="createTime") | |
| 41 | + private Date createTime; | |
| 42 | + @TableField(value="updateTime") | |
| 43 | + private Date updateTime; | |
| 44 | + | |
| 45 | + @TableField(exist=false) | |
| 46 | + private List<SysRole> roles; | |
| 47 | + | |
| 48 | + @TableField(exist=false) | |
| 49 | + private String roleId; | |
| 50 | + | |
| 51 | + @TableField(exist=false) | |
| 52 | + private String oldPassword; | |
| 53 | + @TableField(exist=false) | |
| 54 | + private String newPassword; | |
| 55 | + | |
| 56 | + @Override | |
| 57 | + protected Serializable pkVal() { | |
| 58 | + return null; | |
| 59 | + } | |
| 60 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/model/system/SysUserRole.java
0 → 100644
| ... | ... | @@ -0,0 +1,18 @@ |
| 1 | +package com.sincere.common.model.system; | |
| 2 | + | |
| 3 | +import lombok.Data; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * @Author: [gitgeek] | |
| 7 | + * @Date: [2018-08-06 21:29] | |
| 8 | + * @Description: [ ] | |
| 9 | + * @Version: [1.0.0] | |
| 10 | + * @Copy: [com.zzg] | |
| 11 | + */ | |
| 12 | +@Data | |
| 13 | +public class SysUserRole { | |
| 14 | + | |
| 15 | + private String userId; | |
| 16 | + private String roleId; | |
| 17 | + | |
| 18 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/model/system/constants/UserType.java
0 → 100644
| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | +package com.sincere.common.model.system.constants; | |
| 2 | + | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * @author 作者 owen E-mail: 624191343@qq.com | |
| 6 | + * @version 创建时间:2017年11月12日 上午22:57:51 | |
| 7 | + * 用户类型 | |
| 8 | + */ | |
| 9 | +public enum UserType { | |
| 10 | + | |
| 11 | + /** | |
| 12 | + * 前端app用户 | |
| 13 | + */ | |
| 14 | + APP, | |
| 15 | + /** | |
| 16 | + * 后端管理用户 | |
| 17 | + */ | |
| 18 | + BACKEND | |
| 19 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/props/PermitUrlProperties.java
0 → 100644
| ... | ... | @@ -0,0 +1,55 @@ |
| 1 | +package com.sincere.common.props; | |
| 2 | + | |
| 3 | +import org.springframework.boot.context.properties.ConfigurationProperties; | |
| 4 | + | |
| 5 | +import java.util.ArrayList; | |
| 6 | +import java.util.List; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * @author 作者 owen E-mail: 624191343@qq.com | |
| 10 | + * @version 创建时间:2017年11月12日 上午22:57:51 url白名单处理 application.yml中配置需要放权的url白名单 | |
| 11 | + */ | |
| 12 | +// @ConfigurationProperties(prefix = "permit") | |
| 13 | +@ConfigurationProperties(prefix = "security.oauth2") | |
| 14 | +public class PermitUrlProperties { | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * 监控中心和swagger需要访问的url | |
| 18 | + */ | |
| 19 | + private static final String[] ENDPOINTS = { | |
| 20 | + "/**/actuator/**" , "/**/actuator/**/**" , //断点监控 | |
| 21 | + "/**/v2/api-docs/**", "/**/swagger-ui.html", "/**/swagger-resources/**", "/**/webjars/**", //swagger | |
| 22 | + "/**/turbine.stream","/**/turbine.stream**/**", "/**/hystrix", "/**/hystrix.stream", "/**/hystrix/**", "/**/hystrix/**/**", "/**/proxy.stream/**" , //熔断监控 | |
| 23 | + "/**/druid/**", "/**/favicon.ico", "/**/prometheus" | |
| 24 | + }; | |
| 25 | + | |
| 26 | + private String[] ignored; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 需要放开权限的url | |
| 30 | + * | |
| 31 | + * @param urls | |
| 32 | + * 自定义的url | |
| 33 | + * @return 自定义的url和监控中心需要访问的url集合 | |
| 34 | + */ | |
| 35 | + public String[] getIgnored() { | |
| 36 | + if (ignored == null || ignored.length == 0) { | |
| 37 | + return ENDPOINTS; | |
| 38 | + } | |
| 39 | + | |
| 40 | + List<String> list = new ArrayList<>(); | |
| 41 | + for (String url : ENDPOINTS) { | |
| 42 | + list.add(url); | |
| 43 | + } | |
| 44 | + for (String url : ignored) { | |
| 45 | + list.add(url); | |
| 46 | + } | |
| 47 | + | |
| 48 | + return list.toArray(new String[list.size()]); | |
| 49 | + } | |
| 50 | + | |
| 51 | + public void setIgnored(String[] ignored) { | |
| 52 | + this.ignored = ignored; | |
| 53 | + } | |
| 54 | + | |
| 55 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/util/ApiResult.java
0 → 100644
| ... | ... | @@ -0,0 +1,51 @@ |
| 1 | +package com.sincere.common.util; | |
| 2 | + | |
| 3 | +import com.sincere.common.enums.ResponseCodeEnum; | |
| 4 | +import lombok.Data; | |
| 5 | + | |
| 6 | +import java.io.Serializable; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * @author: yukong | |
| 10 | + * @date: 2018/10/12 10:39 | |
| 11 | + * @description: 统一响应信息主体 | |
| 12 | + */ | |
| 13 | +@Data | |
| 14 | +public class ApiResult<T> implements Serializable { | |
| 15 | + | |
| 16 | + private T data; | |
| 17 | + | |
| 18 | + private Integer code = ResponseCodeEnum.SUCCESS.getCode(); | |
| 19 | + | |
| 20 | + private String message = ResponseCodeEnum.SUCCESS.getMessage(); | |
| 21 | + | |
| 22 | + public ApiResult() { | |
| 23 | + } | |
| 24 | + | |
| 25 | + public ApiResult(T data) { | |
| 26 | + this.data = data; | |
| 27 | + } | |
| 28 | + | |
| 29 | + public ApiResult(T data, String message) { | |
| 30 | + this.data = data; | |
| 31 | + this.message = message; | |
| 32 | + } | |
| 33 | + | |
| 34 | + public ApiResult(T data, ResponseCodeEnum responseCode) { | |
| 35 | + this.data = data; | |
| 36 | + this.code = responseCode.getCode(); | |
| 37 | + this.message = responseCode.getMessage(); | |
| 38 | + } | |
| 39 | + | |
| 40 | + public ApiResult(Throwable throwable) { | |
| 41 | + this.message = throwable.getMessage(); | |
| 42 | + this.code = ResponseCodeEnum.FAIL.getCode(); | |
| 43 | + } | |
| 44 | + | |
| 45 | + public ApiResult(Throwable throwable, ResponseCodeEnum code) { | |
| 46 | + this.message = throwable.getMessage(); | |
| 47 | + this.code = code.getCode(); | |
| 48 | + } | |
| 49 | + | |
| 50 | + | |
| 51 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/util/SpringUtils.java
0 → 100644
| ... | ... | @@ -0,0 +1,37 @@ |
| 1 | +package com.sincere.common.util; | |
| 2 | + | |
| 3 | +import org.springframework.beans.BeansException; | |
| 4 | +import org.springframework.context.ApplicationContext; | |
| 5 | +import org.springframework.context.ApplicationContextAware; | |
| 6 | +import org.springframework.core.env.Environment; | |
| 7 | +import org.springframework.stereotype.Component; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * spring获取bean工具类 | |
| 11 | + * | |
| 12 | +* @author 作者 owen E-mail: 624191343@qq.com | |
| 13 | + * @version 创建时间:2018年3月20日 下午10:13:18 类说明 | |
| 14 | + * | |
| 15 | + */ | |
| 16 | +@Component | |
| 17 | +public class SpringUtils implements ApplicationContextAware { | |
| 18 | + | |
| 19 | + private static ApplicationContext applicationContext = null; | |
| 20 | + | |
| 21 | + @Override | |
| 22 | + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | |
| 23 | + SpringUtils.applicationContext = applicationContext; | |
| 24 | + } | |
| 25 | + | |
| 26 | + public static <T> T getBean(Class<T> cla) { | |
| 27 | + return applicationContext.getBean(cla); | |
| 28 | + } | |
| 29 | + | |
| 30 | + public static <T> T getBean(String name, Class<T> cal) { | |
| 31 | + return applicationContext.getBean(name, cal); | |
| 32 | + } | |
| 33 | + | |
| 34 | + public static String getProperty(String key) { | |
| 35 | + return applicationContext.getBean(Environment.class).getProperty(key); | |
| 36 | + } | |
| 37 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/util/UrlUtil.java
0 → 100644
| ... | ... | @@ -0,0 +1,47 @@ |
| 1 | +package com.sincere.common.util; | |
| 2 | + | |
| 3 | +import javax.servlet.http.HttpServletRequest; | |
| 4 | +import java.io.PrintWriter; | |
| 5 | +import java.io.StringWriter; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * @author: yukong | |
| 9 | + * @date: 2018/11/14 19:50 | |
| 10 | + */ | |
| 11 | +public class UrlUtil { | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * 获取目标主机的ip | |
| 15 | + * @param request | |
| 16 | + * @return | |
| 17 | + */ | |
| 18 | + public static String getRemoteHost(HttpServletRequest request) { | |
| 19 | + String ip = request.getHeader("x-forwarded-for"); | |
| 20 | + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { | |
| 21 | + ip = request.getHeader("Proxy-Client-IP"); | |
| 22 | + } | |
| 23 | + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { | |
| 24 | + ip = request.getHeader("WL-Proxy-Client-IP"); | |
| 25 | + } | |
| 26 | + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { | |
| 27 | + ip = request.getRemoteAddr(); | |
| 28 | + } | |
| 29 | + return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : ip; | |
| 30 | + } | |
| 31 | + | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * 获取完整的异常栈信息 | |
| 35 | + * @param t | |
| 36 | + * @return | |
| 37 | + */ | |
| 38 | + public static String getTrace(Throwable t) { | |
| 39 | + StringWriter stringWriter= new StringWriter(); | |
| 40 | + PrintWriter writer= new PrintWriter(stringWriter); | |
| 41 | + t.printStackTrace(writer); | |
| 42 | + StringBuffer buffer= stringWriter.getBuffer(); | |
| 43 | + return buffer.toString(); | |
| 44 | + } | |
| 45 | + | |
| 46 | + | |
| 47 | +} | ... | ... |
cloud/common/src/main/java/com/sincere/common/util/UserUtil.java
0 → 100644
| ... | ... | @@ -0,0 +1,95 @@ |
| 1 | +package com.sincere.common.util; | |
| 2 | + | |
| 3 | +import com.sincere.common.constants.SecurityConstants; | |
| 4 | +import com.sincere.common.constants.UserConstants; | |
| 5 | +import io.jsonwebtoken.Claims; | |
| 6 | +import io.jsonwebtoken.Jwts; | |
| 7 | +import lombok.extern.slf4j.Slf4j; | |
| 8 | + | |
| 9 | +import javax.servlet.http.HttpServletRequest; | |
| 10 | +import java.util.Base64; | |
| 11 | +import java.util.List; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * @author: yukong | |
| 15 | + * @date: 2018/10/17 08:56 | |
| 16 | + * @description: | |
| 17 | + */ | |
| 18 | +@Slf4j | |
| 19 | +public class UserUtil { | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * 获取请求中的token | |
| 23 | + * @param request | |
| 24 | + * @return token | |
| 25 | + */ | |
| 26 | + public static String getToken(HttpServletRequest request){ | |
| 27 | + String authorization = request.getHeader(SecurityConstants.TOKEN_HEADER); | |
| 28 | + if(authorization == null){ | |
| 29 | + return null; | |
| 30 | + } | |
| 31 | + String token = authorization.split(" ")[1]; | |
| 32 | + log.info("获取token成功,值为{}", token); | |
| 33 | + return token; | |
| 34 | + } | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * 获取jwt中的claims信息 | |
| 38 | + * @param token | |
| 39 | + * @return claim | |
| 40 | + */ | |
| 41 | + public static Claims getClaims(String token) { | |
| 42 | + String key = Base64.getEncoder().encodeToString(SecurityConstants.SIGN_KEY.getBytes()); | |
| 43 | + Claims claims = Jwts.parser().setSigningKey(key).parseClaimsJws(token).getBody(); | |
| 44 | + return claims; | |
| 45 | + } | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * 获取请求中的userId | |
| 49 | + * @param request | |
| 50 | + * @return userId | |
| 51 | + */ | |
| 52 | + public static Integer getUserId(HttpServletRequest request){ | |
| 53 | + String token = getToken(request); | |
| 54 | + if(token == null){ | |
| 55 | + return null; | |
| 56 | + } | |
| 57 | + Claims claims = getClaims(token); | |
| 58 | + Integer userId = (Integer) claims.get(UserConstants.USER_ID); | |
| 59 | + log.info("获取userId成功,值为", userId); | |
| 60 | + return userId; | |
| 61 | + } | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * 获取请求中的userId | |
| 65 | + * @param request | |
| 66 | + * @return userId | |
| 67 | + */ | |
| 68 | + public static String getUserName(HttpServletRequest request){ | |
| 69 | + String token = getToken(request); | |
| 70 | + if(token == null){ | |
| 71 | + return null; | |
| 72 | + } | |
| 73 | + Claims claims = getClaims(token); | |
| 74 | + String username = (String) claims.get(UserConstants.USER_NAME); | |
| 75 | + log.info("获取username成功,值为", username); | |
| 76 | + return username; | |
| 77 | + } | |
| 78 | + | |
| 79 | + /** | |
| 80 | + * 获取请求中的roles集合 | |
| 81 | + * @param request | |
| 82 | + * @return roles | |
| 83 | + */ | |
| 84 | + public static List<String> getRoles(HttpServletRequest request) { | |
| 85 | + String token = getToken(request); | |
| 86 | + if(token == null){ | |
| 87 | + return null; | |
| 88 | + } | |
| 89 | + Claims claims = getClaims(token); | |
| 90 | + List<String> roles = (List<String>) claims.get(UserConstants.AUTHORITIES); | |
| 91 | + return roles; | |
| 92 | + } | |
| 93 | + | |
| 94 | + | |
| 95 | +} | ... | ... |