forked from justauth/JustAuth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into extract-cache
- Loading branch information
Showing
12 changed files
with
391 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.