Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
21f1112c
Commit
21f1112c
authored
May 13, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加对Android的支持
parent
066e7d74
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
3 deletions
+91
-3
WebAspect.java
...ud/src/main/java/com/yanzuoguang/cloud/aop/WebAspect.java
+7
-2
TokenService.java
...main/java/com/yanzuoguang/cloud/service/TokenService.java
+26
-0
TokenHelper.java
...l-db/src/main/java/com/yanzuoguang/token/TokenHelper.java
+39
-1
TokenLoad.java
...til-db/src/main/java/com/yanzuoguang/token/TokenLoad.java
+19
-0
No files found.
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/WebAspect.java
View file @
21f1112c
...
@@ -2,6 +2,7 @@ package com.yanzuoguang.cloud.aop;
...
@@ -2,6 +2,7 @@ package com.yanzuoguang.cloud.aop;
import
com.yanzuoguang.cloud.CloudContans
;
import
com.yanzuoguang.cloud.CloudContans
;
import
com.yanzuoguang.cloud.helper.CookiesHelper
;
import
com.yanzuoguang.cloud.helper.CookiesHelper
;
import
com.yanzuoguang.cloud.service.TokenService
;
import
com.yanzuoguang.util.base.ObjectHelper
;
import
com.yanzuoguang.util.base.ObjectHelper
;
import
com.yanzuoguang.util.contants.ResultConstants
;
import
com.yanzuoguang.util.contants.ResultConstants
;
import
com.yanzuoguang.util.exception.ExceptionHelper
;
import
com.yanzuoguang.util.exception.ExceptionHelper
;
...
@@ -18,6 +19,7 @@ import org.aspectj.lang.annotation.Pointcut;
...
@@ -18,6 +19,7 @@ import org.aspectj.lang.annotation.Pointcut;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
javax.servlet.ServletRequest
;
import
javax.servlet.ServletRequest
;
...
@@ -37,6 +39,9 @@ public class WebAspect extends BaseRequestAspect {
...
@@ -37,6 +39,9 @@ public class WebAspect extends BaseRequestAspect {
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
BaseRequestAspect
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
BaseRequestAspect
.
class
);
@Autowired
private
TokenService
tokenService
;
/**
/**
* exec aop point aspect
* exec aop point aspect
*/
*/
...
@@ -53,13 +58,13 @@ public class WebAspect extends BaseRequestAspect {
...
@@ -53,13 +58,13 @@ public class WebAspect extends BaseRequestAspect {
@Around
(
value
=
"webAspect()"
)
@Around
(
value
=
"webAspect()"
)
public
Object
requestWebAround
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
public
Object
requestWebAround
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
Log
.
threadBegin
();
Log
.
threadBegin
();
CookiesHelper
.
tokenInit
();
// 用户数据库记录
// 用户数据库记录
ResponseResult
responseResult
=
null
;
ResponseResult
responseResult
=
null
;
long
start
=
System
.
currentTimeMillis
();
long
start
=
System
.
currentTimeMillis
();
String
name
=
joinPoint
.
getSignature
().
getName
();
String
name
=
joinPoint
.
getSignature
().
getName
();
try
{
try
{
logger
.
info
(
"[ {} ] request params is {}"
,
name
,
joinPoint
.
getArgs
());
logger
.
info
(
"[ {} ] request params is {}"
,
name
,
joinPoint
.
getArgs
());
tokenService
.
tokenInit
();
Object
result
=
executeMethod
(
joinPoint
,
name
);
Object
result
=
executeMethod
(
joinPoint
,
name
);
if
(
result
instanceof
ResponseResult
)
{
if
(
result
instanceof
ResponseResult
)
{
...
@@ -82,7 +87,7 @@ public class WebAspect extends BaseRequestAspect {
...
@@ -82,7 +87,7 @@ public class WebAspect extends BaseRequestAspect {
throw
e
;
throw
e
;
}
}
}
finally
{
}
finally
{
CookiesHelper
.
tokenFinish
();
tokenService
.
tokenFinish
();
Log
.
threadCommit
();
Log
.
threadCommit
();
saveInterLogs
(
joinPoint
,
responseResult
);
saveInterLogs
(
joinPoint
,
responseResult
);
}
}
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/service/TokenService.java
0 → 100644
View file @
21f1112c
package
com
.
yanzuoguang
.
cloud
.
service
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.stereotype.Component
;
/**
* Token服务
*
* @author 颜佐光
*/
@Component
public
class
TokenService
{
@Autowired
private
ApplicationContext
context
;
public
void
tokenInit
()
{
}
public
void
tokenFinish
()
{
}
}
yzg-util-db/src/main/java/com/yanzuoguang/token/TokenHelper.java
View file @
21f1112c
...
@@ -13,11 +13,36 @@ import com.yanzuoguang.util.vo.MapRow;
...
@@ -13,11 +13,36 @@ import com.yanzuoguang.util.vo.MapRow;
* @author 颜佐光
* @author 颜佐光
*/
*/
public
class
TokenHelper
{
public
class
TokenHelper
{
/**
* 动态加载token支持对象
*/
private
static
TokenLoad
tokenLoad
=
null
;
/**
* 获取动态加载支持对象
*
* @return 动态加载支持对象
*/
public
static
TokenLoad
getTokenLoad
()
{
return
tokenLoad
;
}
/**
* 设置动态加载支持对象
*
* @param tokenLoad 设置值
*/
public
static
void
setTokenLoad
(
TokenLoad
tokenLoad
)
{
TokenHelper
.
tokenLoad
=
tokenLoad
;
}
/**
/**
* 内存缓存
* 内存缓存
*/
*/
protected
static
MemoryCache
<
TokenData
>
cache
=
new
MemoryCache
<>();
protected
static
MemoryCache
<
TokenData
>
cache
=
new
MemoryCache
<>();
/**
/**
* 获取当前线程编号
* 获取当前线程编号
*
*
...
@@ -49,12 +74,25 @@ public class TokenHelper {
...
@@ -49,12 +74,25 @@ public class TokenHelper {
public
static
<
T
extends
Object
>
T
get
(
boolean
checkFlag
,
Class
<
T
>
cls
)
{
public
static
<
T
extends
Object
>
T
get
(
boolean
checkFlag
,
Class
<
T
>
cls
)
{
String
id
=
getCurrentId
();
String
id
=
getCurrentId
();
TokenData
tokenData
=
cache
.
get
(
id
);
TokenData
tokenData
=
cache
.
get
(
id
);
if
(
tokenData
==
null
||
tokenData
.
getData
()
==
null
)
{
if
(
tokenData
==
null
)
{
if
(
checkFlag
)
{
if
(
checkFlag
)
{
throw
new
CodeException
(
"请先登录"
);
throw
new
CodeException
(
"请先登录"
);
}
}
return
null
;
return
null
;
}
}
if
(!
StringHelper
.
isEmpty
(
tokenData
.
getToken
()))
{
tokenData
=
tokenLoad
.
load
(
tokenData
.
getToken
());
if
(
tokenData
!=
null
)
{
cache
.
put
(
id
,
tokenData
);
}
}
if
(
tokenData
.
getData
()
==
null
)
{
if
(
checkFlag
)
{
throw
new
CodeException
(
"请先登录"
);
}
return
null
;
}
if
(
ObjectHelper
.
isSub
(
cls
,
tokenData
.
getData
().
getClass
()))
{
if
(
ObjectHelper
.
isSub
(
cls
,
tokenData
.
getData
().
getClass
()))
{
return
(
T
)
tokenData
.
getData
();
return
(
T
)
tokenData
.
getData
();
}
else
{
}
else
{
...
...
yzg-util-db/src/main/java/com/yanzuoguang/token/TokenLoad.java
0 → 100644
View file @
21f1112c
package
com
.
yanzuoguang
.
token
;
import
com.yanzuoguang.util.vo.MapRow
;
/**
* 动态加载Token
*
* @author 动态加载Token
*/
public
interface
TokenLoad
{
/**
* 动态加载token
*
* @param token 加载标记
* @return 加载内容
*/
TokenData
load
(
String
token
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment