Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
justauth
JustAuth
提交
d4296d16
J
JustAuth
项目概览
justauth
/
JustAuth
1 年多 前同步成功
通知
391
Star
15212
Fork
2708
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
JustAuth
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
未验证
提交
d4296d16
编写于
8月 03, 2019
作者:
智布道
👁
提交者:
GitHub
8月 03, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dev' into extract-cache
上级
3e8c475d
d9967b28
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
391 addition
and
23 deletion
+391
-23
.travis.yml
.travis.yml
+19
-0
README.md
README.md
+9
-0
pom.xml
pom.xml
+20
-6
src/main/java/me/zhyd/oauth/cache/AuthCacheConfig.java
src/main/java/me/zhyd/oauth/cache/AuthCacheConfig.java
+24
-0
src/main/java/me/zhyd/oauth/cache/AuthDefaultCache.java
src/main/java/me/zhyd/oauth/cache/AuthDefaultCache.java
+4
-8
src/main/java/me/zhyd/oauth/log/Log.java
src/main/java/me/zhyd/oauth/log/Log.java
+156
-0
src/main/java/me/zhyd/oauth/request/AuthDefaultRequest.java
src/main/java/me/zhyd/oauth/request/AuthDefaultRequest.java
+2
-2
src/main/java/me/zhyd/oauth/request/AuthMiRequest.java
src/main/java/me/zhyd/oauth/request/AuthMiRequest.java
+3
-7
src/test/java/me/zhyd/oauth/log/LogTest.java
src/test/java/me/zhyd/oauth/log/LogTest.java
+111
-0
src/test/java/me/zhyd/oauth/utils/JsonPathTest.java
src/test/java/me/zhyd/oauth/utils/JsonPathTest.java
+37
-0
update.md
update.md
+6
-0
未找到文件。
.travis.yml
0 → 100644
浏览文件 @
d4296d16
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)
README.md
浏览文件 @
d4296d16
...
...
@@ -17,6 +17,15 @@
<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>
</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>
<center>
...
...
pom.xml
浏览文件 @
d4296d16
...
...
@@ -63,7 +63,7 @@
<junit-version>
4.11
</junit-version>
<fastjson-version>
1.2.58
</fastjson-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>
<dependencies>
...
...
@@ -95,11 +95,6 @@
<version>
${alipay-sdk-version}
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-simple
</artifactId>
<version>
${slf4j-version}
</version>
</dependency>
</dependencies>
<build>
...
...
@@ -190,6 +185,25 @@
<check/>
</configuration>
</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>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-gpg-plugin
</artifactId>
...
...
src/main/java/me/zhyd/oauth/cache/AuthCacheConfig.java
0 → 100644
浏览文件 @
d4296d16
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
;
}
src/main/java/me/zhyd/oauth/cache/AuthDefaultCache.java
浏览文件 @
d4296d16
...
...
@@ -18,12 +18,6 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
*/
public
class
AuthDefaultCache
implements
AuthCache
{
/**
* 默认缓存过期时间:3分钟
* 鉴于授权过程中,根据个人的操作习惯,或者授权平台的不同(google等),每个授权流程的耗时也有差异,不过单个授权流程一般不会太长
* 本缓存工具默认的过期时间设置为3分钟,即程序默认认为3分钟内的授权有效,超过3分钟则默认失效,失效后删除
*/
private
static
final
long
DEF_TIMEOUT
=
3
*
60
*
1000
;
/**
* state cache
*/
...
...
@@ -33,7 +27,9 @@ public class AuthDefaultCache implements AuthCache {
private
final
Lock
readLock
=
cacheLock
.
readLock
();
public
AuthDefaultCache
()
{
this
.
schedulePrune
(
DEF_TIMEOUT
);
if
(
AuthCacheConfig
.
schedulePrune
)
{
this
.
schedulePrune
(
AuthCacheConfig
.
timeout
);
}
}
/**
...
...
@@ -44,7 +40,7 @@ public class AuthDefaultCache implements AuthCache {
*/
@Override
public
void
set
(
String
key
,
String
value
)
{
set
(
key
,
value
,
DEF_TIMEOUT
);
set
(
key
,
value
,
AuthCacheConfig
.
timeout
);
}
/**
...
...
src/main/java/me/zhyd/oauth/log/Log.java
0 → 100644
浏览文件 @
d4296d16
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
;
}
}
src/main/java/me/zhyd/oauth/request/AuthDefaultRequest.java
浏览文件 @
d4296d16
...
...
@@ -9,6 +9,7 @@ import me.zhyd.oauth.config.AuthConfig;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.enums.AuthResponseStatus
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.log.Log
;
import
me.zhyd.oauth.model.AuthCallback
;
import
me.zhyd.oauth.model.AuthResponse
;
import
me.zhyd.oauth.model.AuthToken
;
...
...
@@ -25,7 +26,6 @@ import me.zhyd.oauth.utils.UuidUtils;
* @author yangkai.shen (https://xkcoding.com)
* @since 1.0.0
*/
@Slf4j
public
abstract
class
AuthDefaultRequest
implements
AuthRequest
{
protected
AuthConfig
config
;
protected
AuthSource
source
;
...
...
@@ -82,7 +82,7 @@ public abstract class AuthDefaultRequest implements AuthRequest {
AuthUser
user
=
this
.
getUserInfo
(
authToken
);
return
AuthResponse
.
builder
().
code
(
AuthResponseStatus
.
SUCCESS
.
getCode
()).
data
(
user
).
build
();
}
catch
(
Exception
e
)
{
l
og
.
error
(
"Failed to login with oauth authorization."
,
e
);
L
og
.
error
(
"Failed to login with oauth authorization."
,
e
);
return
this
.
responseError
(
e
);
}
}
...
...
src/main/java/me/zhyd/oauth/request/AuthMiRequest.java
浏览文件 @
d4296d16
...
...
@@ -4,17 +4,14 @@ import cn.hutool.core.util.StrUtil;
import
cn.hutool.http.HttpRequest
;
import
cn.hutool.http.HttpResponse
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.extern.slf4j.Slf4j
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.enums.AuthResponseStatus
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthCallback
;
import
me.zhyd.oauth.model.AuthResponse
;
import
me.zhyd.oauth.model.AuthToken
;
import
me.zhyd.oauth.model.AuthUser
;
import
me.zhyd.oauth.log.Log
;
import
me.zhyd.oauth.model.*
;
import
me.zhyd.oauth.utils.UrlBuilder
;
import
java.text.MessageFormat
;
...
...
@@ -25,7 +22,6 @@ import java.text.MessageFormat;
* @author yangkai.shen (https://xkcoding.com)
* @since 1.5.0
*/
@Slf4j
public
class
AuthMiRequest
extends
AuthDefaultRequest
{
private
static
final
String
PREFIX
=
"&&&START&&&"
;
...
...
@@ -96,7 +92,7 @@ public class AuthMiRequest extends AuthDefaultRequest {
JSONObject
emailPhone
=
userEmailPhone
.
getJSONObject
(
"data"
);
authUser
.
setEmail
(
emailPhone
.
getString
(
"email"
));
}
else
{
l
og
.
warn
(
"小米开发平台暂时不对外开放用户手机及邮箱信息的获取"
);
L
og
.
warn
(
"小米开发平台暂时不对外开放用户手机及邮箱信息的获取"
);
}
return
authUser
;
...
...
src/test/java/me/zhyd/oauth/log/LogTest.java
0 → 100644
浏览文件 @
d4296d16
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
();
}
}
src/test/java/me/zhyd/oauth/utils/
Custom
Test.java
→
src/test/java/me/zhyd/oauth/utils/
JsonPath
Test.java
浏览文件 @
d4296d16
...
...
@@ -11,64 +11,14 @@ import java.util.List;
import
java.util.Map
;
/**
*
其他测试方法
*
JsonPath用法测试
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
*/
public
class
Custom
Test
{
public
class
JsonPath
Test
{
/**
* 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
()
{
public
void
jsonPath
()
{
List
<
Map
<
String
,
Map
<
String
,
Object
>>>
list
=
new
ArrayList
<>();
Map
<
String
,
Map
<
String
,
Object
>>
map
=
new
HashMap
<>();
...
...
update.md
浏览文件 @
d4296d16
### 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))
`v1.9.4`
版本发布失败,请升级到
`1.9.5`
版本!
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录