Merge branch 'dev' into extract-cache
This commit is contained in:
19
.travis.yml
Normal file
19
.travis.yml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
language: java
|
||||||
|
|
||||||
|
sudo: false # faster builds
|
||||||
|
|
||||||
|
install: true
|
||||||
|
|
||||||
|
jdk:
|
||||||
|
- openjdk8
|
||||||
|
|
||||||
|
notifications:
|
||||||
|
email: false
|
||||||
|
|
||||||
|
script:
|
||||||
|
- export TZ=Asia/Shanghai
|
||||||
|
- mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
|
||||||
|
- mvn cobertura:cobertura -Dcobertura.report.format=xml -Dmaven.javadoc.skip.true
|
||||||
|
|
||||||
|
after_success:
|
||||||
|
- bash <(curl -s https://codecov.io/bash)
|
||||||
@@ -17,6 +17,15 @@
|
|||||||
<a target="_blank" href="https://apidoc.gitee.com/yadong.zhang/JustAuth/">
|
<a target="_blank" href="https://apidoc.gitee.com/yadong.zhang/JustAuth/">
|
||||||
<img src="https://img.shields.io/badge/Docs-1.9.5-orange.svg" ></img>
|
<img src="https://img.shields.io/badge/Docs-1.9.5-orange.svg" ></img>
|
||||||
</a>
|
</a>
|
||||||
|
<a href="https://codecov.io/gh/zhangyd-c/JustAuth">
|
||||||
|
<img src="https://codecov.io/gh/zhangyd-c/JustAuth/branch/master/graph/badge.svg" />
|
||||||
|
</a>
|
||||||
|
<a href='https://gitee.com/yadong.zhang/JustAuth/stargazers'>
|
||||||
|
<img src='https://gitee.com/yadong.zhang/JustAuth/badge/star.svg?theme=white' alt='star'></img>
|
||||||
|
</a>
|
||||||
|
<a target="_blank" href='https://github.com/zhangyd-c/JustAuth'>
|
||||||
|
<img src="https://img.shields.io/github/stars/zhangyd-c/JustAuth.svg?style=social" alt="github star"></img>
|
||||||
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<center>
|
<center>
|
||||||
|
|||||||
26
pom.xml
26
pom.xml
@@ -63,7 +63,7 @@
|
|||||||
<junit-version>4.11</junit-version>
|
<junit-version>4.11</junit-version>
|
||||||
<fastjson-version>1.2.58</fastjson-version>
|
<fastjson-version>1.2.58</fastjson-version>
|
||||||
<alipay-sdk-version>3.7.4.ALL</alipay-sdk-version>
|
<alipay-sdk-version>3.7.4.ALL</alipay-sdk-version>
|
||||||
<slf4j-version>1.7.25</slf4j-version>
|
<jacoco-version>0.8.2</jacoco-version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -95,11 +95,6 @@
|
|||||||
<version>${alipay-sdk-version}</version>
|
<version>${alipay-sdk-version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-simple</artifactId>
|
|
||||||
<version>${slf4j-version}</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -190,6 +185,25 @@
|
|||||||
<check/>
|
<check/>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.jacoco</groupId>
|
||||||
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
|
<version>${jacoco-version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>prepare-agent</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>report</id>
|
||||||
|
<phase>test</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>report</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-gpg-plugin</artifactId>
|
<artifactId>maven-gpg-plugin</artifactId>
|
||||||
|
|||||||
24
src/main/java/me/zhyd/oauth/cache/AuthCacheConfig.java
vendored
Normal file
24
src/main/java/me/zhyd/oauth/cache/AuthCacheConfig.java
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package me.zhyd.oauth.cache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AuthCache配置类
|
||||||
|
*
|
||||||
|
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2019/8/1 17:15
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public class AuthCacheConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认缓存过期时间:3分钟
|
||||||
|
* 鉴于授权过程中,根据个人的操作习惯,或者授权平台的不同(google等),每个授权流程的耗时也有差异,不过单个授权流程一般不会太长
|
||||||
|
* 本缓存工具默认的过期时间设置为3分钟,即程序默认认为3分钟内的授权有效,超过3分钟则默认失效,失效后删除
|
||||||
|
*/
|
||||||
|
public static long timeout = 3 * 60 * 1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否开启定时{@link AuthDefaultCache#pruneCache()}的任务
|
||||||
|
*/
|
||||||
|
public static boolean schedulePrune = true;
|
||||||
|
}
|
||||||
@@ -18,12 +18,6 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|||||||
*/
|
*/
|
||||||
public class AuthDefaultCache implements AuthCache {
|
public class AuthDefaultCache implements AuthCache {
|
||||||
|
|
||||||
/**
|
|
||||||
* 默认缓存过期时间:3分钟
|
|
||||||
* 鉴于授权过程中,根据个人的操作习惯,或者授权平台的不同(google等),每个授权流程的耗时也有差异,不过单个授权流程一般不会太长
|
|
||||||
* 本缓存工具默认的过期时间设置为3分钟,即程序默认认为3分钟内的授权有效,超过3分钟则默认失效,失效后删除
|
|
||||||
*/
|
|
||||||
private static final long DEF_TIMEOUT = 3 * 60 * 1000;
|
|
||||||
/**
|
/**
|
||||||
* state cache
|
* state cache
|
||||||
*/
|
*/
|
||||||
@@ -33,7 +27,9 @@ public class AuthDefaultCache implements AuthCache {
|
|||||||
private final Lock readLock = cacheLock.readLock();
|
private final Lock readLock = cacheLock.readLock();
|
||||||
|
|
||||||
public AuthDefaultCache() {
|
public AuthDefaultCache() {
|
||||||
this.schedulePrune(DEF_TIMEOUT);
|
if (AuthCacheConfig.schedulePrune) {
|
||||||
|
this.schedulePrune(AuthCacheConfig.timeout);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,7 +40,7 @@ public class AuthDefaultCache implements AuthCache {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void set(String key, String value) {
|
public void set(String key, String value) {
|
||||||
set(key, value, DEF_TIMEOUT);
|
set(key, value, AuthCacheConfig.timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
156
src/main/java/me/zhyd/oauth/log/Log.java
Normal file
156
src/main/java/me/zhyd/oauth/log/Log.java
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
package me.zhyd.oauth.log;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 针对JustAuth提供的轻量级的日志打印工具
|
||||||
|
*
|
||||||
|
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2019/8/1 17:14
|
||||||
|
* @see Log#debug(String)
|
||||||
|
* @see Log#debug(String, Throwable)
|
||||||
|
* @see Log#warn(String)
|
||||||
|
* @see Log#warn(String, Throwable)
|
||||||
|
* @see Log#error(String)
|
||||||
|
* @see Log#error(String, Throwable)
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public class Log {
|
||||||
|
|
||||||
|
public static void debug(String msg) {
|
||||||
|
debug(msg, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void warn(String msg) {
|
||||||
|
warn(msg, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void error(String msg) {
|
||||||
|
error(msg, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void debug(String msg, Throwable t) {
|
||||||
|
print(Level.DEBUG, msg, t, System.out);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void warn(String msg, Throwable t) {
|
||||||
|
print(Level.WARN, msg, t, System.out);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void error(String msg, Throwable t) {
|
||||||
|
print(Level.ERROR, msg, t, System.err);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打印日志内容,格式:2019-08-02 20:44:07 main me.zhyd.oauth.log.Log(debug:39) [DEBUG] - xxxx
|
||||||
|
*
|
||||||
|
* @param level 日志级别
|
||||||
|
* @param msg 日志内容
|
||||||
|
* @param t 异常信息
|
||||||
|
* @param ps 实际执行打印的PrintStream
|
||||||
|
*/
|
||||||
|
private static void print(Level level, String msg, Throwable t, PrintStream ps) {
|
||||||
|
if (Config.enable) {
|
||||||
|
if (level.getLevelNum() >= Config.level.getLevelNum()) {
|
||||||
|
ps.println(String.format("%s %s %s [%s] - %s", getDate(), Thread.currentThread().getName(), getCaller(), level, msg));
|
||||||
|
writeThrowable(t, ps);
|
||||||
|
ps.flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取调用方的信息
|
||||||
|
*
|
||||||
|
* @return 返回调用方的信息,格式:class(method:lineNumber)
|
||||||
|
*/
|
||||||
|
private static String getCaller() {
|
||||||
|
int offset = 2;
|
||||||
|
StackTraceElement[] stackTraceArr = (new Throwable()).getStackTrace();
|
||||||
|
StackTraceElement stackTrace = null;
|
||||||
|
if (offset >= stackTraceArr.length) {
|
||||||
|
offset = offset - 1;
|
||||||
|
}
|
||||||
|
stackTrace = stackTraceArr[offset];
|
||||||
|
return stackTrace.getClassName() +
|
||||||
|
"(" +
|
||||||
|
stackTrace.getMethodName() +
|
||||||
|
':' +
|
||||||
|
stackTrace.getLineNumber() +
|
||||||
|
")";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取格式化后的日期
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private static String getDate() {
|
||||||
|
return LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打印异常信息
|
||||||
|
*
|
||||||
|
* @param t 异常
|
||||||
|
* @param targetStream 实际执行打印的PrintStream
|
||||||
|
*/
|
||||||
|
private static void writeThrowable(Throwable t, PrintStream targetStream) {
|
||||||
|
if (t != null) {
|
||||||
|
t.printStackTrace(targetStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志级别
|
||||||
|
*
|
||||||
|
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2019/8/2 19:49
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum Level {
|
||||||
|
/**
|
||||||
|
* DEBUG: 普通级别
|
||||||
|
*/
|
||||||
|
DEBUG(10),
|
||||||
|
/**
|
||||||
|
* WARN: 警告级别
|
||||||
|
*/
|
||||||
|
WARN(30),
|
||||||
|
/**
|
||||||
|
* ERROR: 异常级别
|
||||||
|
*/
|
||||||
|
ERROR(40);
|
||||||
|
|
||||||
|
private int levelNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志配置
|
||||||
|
*
|
||||||
|
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2019/8/1 17:14
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
static class Config {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 需要打印的日志级别
|
||||||
|
*/
|
||||||
|
static Level level = Level.DEBUG;
|
||||||
|
/**
|
||||||
|
* 是否启用日志打印功能,默认启用
|
||||||
|
*/
|
||||||
|
static boolean enable = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ import me.zhyd.oauth.config.AuthConfig;
|
|||||||
import me.zhyd.oauth.config.AuthSource;
|
import me.zhyd.oauth.config.AuthSource;
|
||||||
import me.zhyd.oauth.enums.AuthResponseStatus;
|
import me.zhyd.oauth.enums.AuthResponseStatus;
|
||||||
import me.zhyd.oauth.exception.AuthException;
|
import me.zhyd.oauth.exception.AuthException;
|
||||||
|
import me.zhyd.oauth.log.Log;
|
||||||
import me.zhyd.oauth.model.AuthCallback;
|
import me.zhyd.oauth.model.AuthCallback;
|
||||||
import me.zhyd.oauth.model.AuthResponse;
|
import me.zhyd.oauth.model.AuthResponse;
|
||||||
import me.zhyd.oauth.model.AuthToken;
|
import me.zhyd.oauth.model.AuthToken;
|
||||||
@@ -25,7 +26,6 @@ import me.zhyd.oauth.utils.UuidUtils;
|
|||||||
* @author yangkai.shen (https://xkcoding.com)
|
* @author yangkai.shen (https://xkcoding.com)
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
|
||||||
public abstract class AuthDefaultRequest implements AuthRequest {
|
public abstract class AuthDefaultRequest implements AuthRequest {
|
||||||
protected AuthConfig config;
|
protected AuthConfig config;
|
||||||
protected AuthSource source;
|
protected AuthSource source;
|
||||||
@@ -82,7 +82,7 @@ public abstract class AuthDefaultRequest implements AuthRequest {
|
|||||||
AuthUser user = this.getUserInfo(authToken);
|
AuthUser user = this.getUserInfo(authToken);
|
||||||
return AuthResponse.builder().code(AuthResponseStatus.SUCCESS.getCode()).data(user).build();
|
return AuthResponse.builder().code(AuthResponseStatus.SUCCESS.getCode()).data(user).build();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Failed to login with oauth authorization.", e);
|
Log.error("Failed to login with oauth authorization.", e);
|
||||||
return this.responseError(e);
|
return this.responseError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,17 +4,14 @@ import cn.hutool.core.util.StrUtil;
|
|||||||
import cn.hutool.http.HttpRequest;
|
import cn.hutool.http.HttpRequest;
|
||||||
import cn.hutool.http.HttpResponse;
|
import cn.hutool.http.HttpResponse;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import me.zhyd.oauth.cache.AuthStateCache;
|
import me.zhyd.oauth.cache.AuthStateCache;
|
||||||
import me.zhyd.oauth.config.AuthConfig;
|
import me.zhyd.oauth.config.AuthConfig;
|
||||||
import me.zhyd.oauth.config.AuthSource;
|
import me.zhyd.oauth.config.AuthSource;
|
||||||
import me.zhyd.oauth.enums.AuthResponseStatus;
|
import me.zhyd.oauth.enums.AuthResponseStatus;
|
||||||
import me.zhyd.oauth.enums.AuthUserGender;
|
import me.zhyd.oauth.enums.AuthUserGender;
|
||||||
import me.zhyd.oauth.exception.AuthException;
|
import me.zhyd.oauth.exception.AuthException;
|
||||||
import me.zhyd.oauth.model.AuthCallback;
|
import me.zhyd.oauth.log.Log;
|
||||||
import me.zhyd.oauth.model.AuthResponse;
|
import me.zhyd.oauth.model.*;
|
||||||
import me.zhyd.oauth.model.AuthToken;
|
|
||||||
import me.zhyd.oauth.model.AuthUser;
|
|
||||||
import me.zhyd.oauth.utils.UrlBuilder;
|
import me.zhyd.oauth.utils.UrlBuilder;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
@@ -25,7 +22,6 @@ import java.text.MessageFormat;
|
|||||||
* @author yangkai.shen (https://xkcoding.com)
|
* @author yangkai.shen (https://xkcoding.com)
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
|
||||||
public class AuthMiRequest extends AuthDefaultRequest {
|
public class AuthMiRequest extends AuthDefaultRequest {
|
||||||
private static final String PREFIX = "&&&START&&&";
|
private static final String PREFIX = "&&&START&&&";
|
||||||
|
|
||||||
@@ -96,7 +92,7 @@ public class AuthMiRequest extends AuthDefaultRequest {
|
|||||||
JSONObject emailPhone = userEmailPhone.getJSONObject("data");
|
JSONObject emailPhone = userEmailPhone.getJSONObject("data");
|
||||||
authUser.setEmail(emailPhone.getString("email"));
|
authUser.setEmail(emailPhone.getString("email"));
|
||||||
} else {
|
} else {
|
||||||
log.warn("小米开发平台暂时不对外开放用户手机及邮箱信息的获取");
|
Log.warn("小米开发平台暂时不对外开放用户手机及邮箱信息的获取");
|
||||||
}
|
}
|
||||||
|
|
||||||
return authUser;
|
return authUser;
|
||||||
|
|||||||
111
src/test/java/me/zhyd/oauth/log/LogTest.java
Normal file
111
src/test/java/me/zhyd/oauth/log/LogTest.java
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
package me.zhyd.oauth.log;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2019/8/2 19:36
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public class LogTest {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// 测试正常打印
|
||||||
|
Log.debug("[1] This is a test.");
|
||||||
|
Log.debug("[1] This is a test.", new NullPointerException("npe"));
|
||||||
|
|
||||||
|
Log.warn("[1] This is a test.");
|
||||||
|
Log.warn("[1] This is a test.", new NullPointerException("npe"));
|
||||||
|
|
||||||
|
Log.error("[1] This is a test.");
|
||||||
|
Log.error("[1] This is a test.", new NullPointerException("npe"));
|
||||||
|
|
||||||
|
// 测试只打印 error级别的日志
|
||||||
|
Log.Config.level = Log.Level.ERROR;
|
||||||
|
|
||||||
|
Log.debug("[2] This is a test.");
|
||||||
|
Log.warn("[2] This is a test.");
|
||||||
|
Log.error("[2] This is a test.");
|
||||||
|
|
||||||
|
// 测试关闭日志
|
||||||
|
Log.Config.enable = false;
|
||||||
|
|
||||||
|
Log.debug("[3] This is a test.");
|
||||||
|
Log.warn("[3] This is a test.");
|
||||||
|
Log.error("[3] This is a test.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1000000: 23135ms
|
||||||
|
* 100000: 3016ms
|
||||||
|
* 10000: 328ms
|
||||||
|
* 1000: 26ms
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testByThread() {
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
for (int i = 0; i < 1; i++) {
|
||||||
|
System.out.println(callMethodByThread());
|
||||||
|
}
|
||||||
|
long end = System.currentTimeMillis();
|
||||||
|
System.out.println((end - start) + "ms");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1000000: 19058ms
|
||||||
|
* 100000: 2772ms
|
||||||
|
* 10000: 323ms
|
||||||
|
* 1000: 29ms
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testByThrowable() {
|
||||||
|
long end = System.currentTimeMillis();
|
||||||
|
for (int i = 0; i < 1; i++) {
|
||||||
|
System.out.println(callMethodByThrowable());
|
||||||
|
}
|
||||||
|
long end2 = System.currentTimeMillis();
|
||||||
|
System.out.println((end2 - end) + "ms");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBySecurityManager() {
|
||||||
|
long end = System.currentTimeMillis();
|
||||||
|
for (int i = 0; i < 1; i++) {
|
||||||
|
System.out.println(callMethodBySecurityManager());
|
||||||
|
}
|
||||||
|
long end2 = System.currentTimeMillis();
|
||||||
|
System.out.println((end2 - end) + "ms");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private String callMethodByThread() {
|
||||||
|
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||||
|
for (StackTraceElement stackTraceElement : stackTrace) {
|
||||||
|
System.out.println(stackTraceElement.getMethodName());
|
||||||
|
}
|
||||||
|
return stackTrace[2].getMethodName();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String callMethodByThrowable() {
|
||||||
|
StackTraceElement[] stackTrace = (new Throwable()).getStackTrace();
|
||||||
|
for (StackTraceElement stackTraceElement : stackTrace) {
|
||||||
|
System.out.println(stackTraceElement.getMethodName());
|
||||||
|
}
|
||||||
|
return stackTrace[2].getMethodName();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String callMethodBySecurityManager() {
|
||||||
|
return new SecurityManager() {
|
||||||
|
String getClassName() {
|
||||||
|
for (Class clazz : getClassContext()) {
|
||||||
|
System.out.println(clazz);
|
||||||
|
}
|
||||||
|
return getClassContext()[0].getName();
|
||||||
|
}
|
||||||
|
}.getClassName();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
package me.zhyd.oauth.utils;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.alibaba.fastjson.JSONPath;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 其他测试方法
|
|
||||||
*
|
|
||||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
|
||||||
*/
|
|
||||||
public class CustomTest {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 1000000: 23135ms
|
|
||||||
* 100000: 3016ms
|
|
||||||
* 10000: 328ms
|
|
||||||
* 1000: 26ms
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void test() {
|
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
for (int i = 0; i < 1000; i++) {
|
|
||||||
callMethod();
|
|
||||||
}
|
|
||||||
long end = System.currentTimeMillis();
|
|
||||||
System.out.println((end - start) + "ms");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 1000000: 19058ms
|
|
||||||
* 100000: 2772ms
|
|
||||||
* 10000: 323ms
|
|
||||||
* 1000: 29ms
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void test2() {
|
|
||||||
long end = System.currentTimeMillis();
|
|
||||||
for (int i = 0; i < 1000; i++) {
|
|
||||||
callMethod2();
|
|
||||||
}
|
|
||||||
long end2 = System.currentTimeMillis();
|
|
||||||
System.out.println((end2 - end) + "ms");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public String callMethod() {
|
|
||||||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
|
||||||
// for (StackTraceElement stackTraceElement : stackTrace) {
|
|
||||||
// System.out.println(stackTraceElement.getMethodName());
|
|
||||||
// }
|
|
||||||
return stackTrace[2].getMethodName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String callMethod2() {
|
|
||||||
StackTraceElement[] stackTrace = (new Throwable()).getStackTrace();
|
|
||||||
// for (StackTraceElement stackTraceElement : stackTrace) {
|
|
||||||
// System.out.println(stackTraceElement.getMethodName());
|
|
||||||
// }
|
|
||||||
return stackTrace[2].getMethodName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void jsonpath() {
|
|
||||||
List<Map<String, Map<String, Object>>> list = new ArrayList<>();
|
|
||||||
|
|
||||||
Map<String, Map<String, Object>> map = new HashMap<>();
|
|
||||||
Map<String, Object> node = new HashMap<>();
|
|
||||||
node.put("emailAddress", "xxxx");
|
|
||||||
map.put("handle~", node);
|
|
||||||
list.add(map);
|
|
||||||
|
|
||||||
|
|
||||||
Map<String, Object> master = new HashMap<>();
|
|
||||||
// master.put("elements", list);
|
|
||||||
JSONObject emailObj = JSONObject.parseObject(JSON.toJSONString(master));
|
|
||||||
Object object = JSONPath.eval(emailObj, "$['elements'][0]['handle~']['emailAddress']");
|
|
||||||
System.out.println(object);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
37
src/test/java/me/zhyd/oauth/utils/JsonPathTest.java
Normal file
37
src/test/java/me/zhyd/oauth/utils/JsonPathTest.java
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package me.zhyd.oauth.utils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.JSONPath;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JsonPath用法测试
|
||||||
|
*
|
||||||
|
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||||
|
*/
|
||||||
|
public class JsonPathTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void jsonPath() {
|
||||||
|
List<Map<String, Map<String, Object>>> list = new ArrayList<>();
|
||||||
|
|
||||||
|
Map<String, Map<String, Object>> map = new HashMap<>();
|
||||||
|
Map<String, Object> node = new HashMap<>();
|
||||||
|
node.put("emailAddress", "xxxx");
|
||||||
|
map.put("handle~", node);
|
||||||
|
list.add(map);
|
||||||
|
|
||||||
|
|
||||||
|
Map<String, Object> master = new HashMap<>();
|
||||||
|
// master.put("elements", list);
|
||||||
|
JSONObject emailObj = JSONObject.parseObject(JSON.toJSONString(master));
|
||||||
|
Object object = JSONPath.eval(emailObj, "$['elements'][0]['handle~']['emailAddress']");
|
||||||
|
System.out.println(object);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
|
### 2019/08/02
|
||||||
|
|
||||||
|
- 增加`AuthCache`配置类`AuthCacheConfig.java`,可以自定义缓存有效期以及是否开启定时任务
|
||||||
|
- 去掉`slf4j`依赖,封装`Log.java`工具类
|
||||||
|
- 规范测试类
|
||||||
|
|
||||||
### 2019/07/31 ([v1.9.5](https://gitee.com/yadong.zhang/JustAuth/releases/v1.9.5))
|
### 2019/07/31 ([v1.9.5](https://gitee.com/yadong.zhang/JustAuth/releases/v1.9.5))
|
||||||
|
|
||||||
`v1.9.4`版本发布失败,请升级到`1.9.5`版本!
|
`v1.9.4`版本发布失败,请升级到`1.9.5`版本!
|
||||||
|
|||||||
Reference in New Issue
Block a user