Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
XKZJ_WCL
JustAuth
提交
267b74be
J
JustAuth
项目概览
XKZJ_WCL
/
JustAuth
与 Fork 源项目一致
Fork自
justauth / JustAuth
通知
1
Star
0
Fork
0
代码
文件
提交
分支
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
267b74be
编写于
8月 02, 2019
作者:
智布道
👁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
📝
增加缓存配置、去掉slf4j依赖、增加Log工具类等
上级
6474c465
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
312 addition
and
19 deletion
+312
-19
pom.xml
pom.xml
+0
-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
+126
-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
+2
-3
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
未找到文件。
pom.xml
浏览文件 @
267b74be
...
...
@@ -63,7 +63,6 @@
<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>
...
...
@@ -96,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>
...
...
src/main/java/me/zhyd/oauth/cache/AuthCacheConfig.java
0 → 100644
浏览文件 @
267b74be
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
浏览文件 @
267b74be
...
...
@@ -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
浏览文件 @
267b74be
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
* @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
);
}
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
();
}
}
}
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
()
+
")"
;
}
private
static
String
getDate
()
{
return
LocalDateTime
.
now
().
format
(
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
));
}
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
浏览文件 @
267b74be
...
...
@@ -8,6 +8,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
;
...
...
@@ -24,7 +25,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
;
...
...
@@ -75,7 +75,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
浏览文件 @
267b74be
...
...
@@ -4,12 +4,12 @@ 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.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.log.Log
;
import
me.zhyd.oauth.model.*
;
import
me.zhyd.oauth.utils.UrlBuilder
;
...
...
@@ -21,7 +21,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&&&"
;
...
...
@@ -88,7 +87,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
浏览文件 @
267b74be
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
浏览文件 @
267b74be
...
...
@@ -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
浏览文件 @
267b74be
### 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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录