Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
brandkbs2
Overview
Overview
Details
Activity
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
shenjunjie
brandkbs2
Commits
981cbd0f
Commit
981cbd0f
authored
Mar 29, 2023
by
shenjunjie
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature' into 'release'
Feature See merge request
!287
parents
e8257af2
b7de37e2
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
9 deletions
+13
-9
src/main/java/com/zhiwei/brandkbs2/aop/AopLogRecord.java
+9
-2
src/main/java/com/zhiwei/brandkbs2/auth/AuthAspect.java
+1
-1
src/main/java/com/zhiwei/brandkbs2/interceptor/MainAuthInterceptor.java
+1
-1
src/main/java/com/zhiwei/brandkbs2/util/Tools.java
+2
-5
No files found.
src/main/java/com/zhiwei/brandkbs2/aop/AopLogRecord.java
View file @
981cbd0f
...
@@ -16,6 +16,8 @@ import io.swagger.annotations.Api;
...
@@ -16,6 +16,8 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.annotation.AfterReturning
;
import
org.aspectj.lang.annotation.AfterReturning
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Aspect
;
...
@@ -31,7 +33,6 @@ import javax.servlet.ServletRequest;
...
@@ -31,7 +33,6 @@ import javax.servlet.ServletRequest;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.net.InetAddress
;
import
java.net.InetAddress
;
import
java.net.UnknownHostException
;
import
java.util.*
;
import
java.util.*
;
import
static
java
.
util
.
Objects
.
nonNull
;
import
static
java
.
util
.
Objects
.
nonNull
;
...
@@ -45,6 +46,8 @@ import static java.util.Objects.nonNull;
...
@@ -45,6 +46,8 @@ import static java.util.Objects.nonNull;
@Aspect
@Aspect
@Component
@Component
public
class
AopLogRecord
{
public
class
AopLogRecord
{
public
static
final
Logger
log
=
LogManager
.
getLogger
(
AopLogRecord
.
class
);
@Value
(
"${jwt.key}"
)
@Value
(
"${jwt.key}"
)
private
String
jwtKey
;
private
String
jwtKey
;
@Resource
(
name
=
"userServiceImpl"
)
@Resource
(
name
=
"userServiceImpl"
)
...
@@ -58,7 +61,8 @@ public class AopLogRecord {
...
@@ -58,7 +61,8 @@ public class AopLogRecord {
private
static
final
List
<
String
>
URL_PATTERNS
=
Arrays
.
asList
(
"/getNewAll"
,
"/getNew"
,
"/schedule"
);
private
static
final
List
<
String
>
URL_PATTERNS
=
Arrays
.
asList
(
"/getNewAll"
,
"/getNew"
,
"/schedule"
);
@AfterReturning
(
value
=
"execution(public * com..controller..admin..*Controller.*(..)) || execution(* com..controller..app..*Controller.*(..)) || execution(* com..controller..LoginController.checkBind())"
,
returning
=
"ResponseResult"
)
@AfterReturning
(
value
=
"execution(public * com..controller..admin..*Controller.*(..)) || execution(* com..controller..app..*Controller.*(..)) || execution(* com..controller..LoginController.checkBind())"
,
returning
=
"ResponseResult"
)
private
void
beforeLog
(
JoinPoint
joinPoint
,
ResponseResult
ResponseResult
)
throws
UnknownHostException
,
ClassNotFoundException
{
private
void
beforeLog
(
JoinPoint
joinPoint
,
ResponseResult
ResponseResult
){
try
{
long
now
=
System
.
currentTimeMillis
();
long
now
=
System
.
currentTimeMillis
();
// RequestContextHolder 顾名思义 持有 request 上下文的容器
// RequestContextHolder 顾名思义 持有 request 上下文的容器
ServletRequestAttributes
requestAttributes
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
ServletRequestAttributes
requestAttributes
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
...
@@ -110,6 +114,9 @@ public class AopLogRecord {
...
@@ -110,6 +114,9 @@ public class AopLogRecord {
behaviorDao
.
insertOneWithoutId
(
behavior
,
collectionName
);
behaviorDao
.
insertOneWithoutId
(
behavior
,
collectionName
);
}
}
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"beforeLog"
,
e
);
}
}
}
private
UserLogRecord
userLogRecord
(
String
projectId
,
UserInfo
userInfo
,
JoinPoint
joinPoint
,
MethodSignature
methodSignature
,
ResponseResult
responseResult
)
{
private
UserLogRecord
userLogRecord
(
String
projectId
,
UserInfo
userInfo
,
JoinPoint
joinPoint
,
MethodSignature
methodSignature
,
ResponseResult
responseResult
)
{
...
...
src/main/java/com/zhiwei/brandkbs2/auth/AuthAspect.java
View file @
981cbd0f
...
@@ -70,7 +70,7 @@ public class AuthAspect {
...
@@ -70,7 +70,7 @@ public class AuthAspect {
}
}
String
token
=
request
.
getHeader
(
jwtKey
);
String
token
=
request
.
getHeader
(
jwtKey
);
// 存在有效token
// 存在有效token
if
(
null
!=
token
&&
!
Tools
.
tokenEmpty
(
token
))
{
if
(
null
!=
token
&&
!
Tools
.
isNullOrUndefined
(
token
))
{
Object
proceed
;
Object
proceed
;
try
{
try
{
Map
<
String
,
Object
>
tokenInfo
=
JwtUtil
.
unsign
(
token
,
Map
.
class
);
Map
<
String
,
Object
>
tokenInfo
=
JwtUtil
.
unsign
(
token
,
Map
.
class
);
...
...
src/main/java/com/zhiwei/brandkbs2/interceptor/MainAuthInterceptor.java
View file @
981cbd0f
...
@@ -53,7 +53,7 @@ public class MainAuthInterceptor implements HandlerInterceptor {
...
@@ -53,7 +53,7 @@ public class MainAuthInterceptor implements HandlerInterceptor {
String
token
=
request
.
getHeader
(
"Token"
);
String
token
=
request
.
getHeader
(
"Token"
);
try
{
try
{
// 不存在token 重新获取token
// 不存在token 重新获取token
if
(
Tools
.
tokenEmpty
(
token
))
{
if
(
Tools
.
isNullOrUndefined
(
token
))
{
Tools
.
responseMessage
(
response
,
HttpServletResponse
.
SC_UNAUTHORIZED
,
new
ResponseResult
(
CommonCodeEnum
.
UNAUTHENTICATED
,
null
));
Tools
.
responseMessage
(
response
,
HttpServletResponse
.
SC_UNAUTHORIZED
,
new
ResponseResult
(
CommonCodeEnum
.
UNAUTHENTICATED
,
null
));
return
false
;
return
false
;
}
}
...
...
src/main/java/com/zhiwei/brandkbs2/util/Tools.java
View file @
981cbd0f
...
@@ -649,10 +649,6 @@ public class Tools {
...
@@ -649,10 +649,6 @@ public class Tools {
}
}
}
}
public
static
boolean
tokenEmpty
(
String
token
)
{
return
null
==
token
||
Objects
.
equals
(
"undefined"
,
token
)
||
Objects
.
equals
(
"null"
,
token
);
}
/**
/**
* 获得区段时间的最大最小值
* 获得区段时间的最大最小值
*
*
...
@@ -1027,6 +1023,6 @@ public class Tools {
...
@@ -1027,6 +1023,6 @@ public class Tools {
* @return
* @return
*/
*/
public
static
boolean
isNullOrUndefined
(
Object
o
)
{
public
static
boolean
isNullOrUndefined
(
Object
o
)
{
return
(
isEmpty
(
o
)
||
Objects
.
equals
(
"undefined"
,
o
));
return
(
isEmpty
(
o
)
||
Objects
.
equals
(
"undefined"
,
o
)
||
Objects
.
equals
(
"null"
,
o
)
);
}
}
}
}
\ No newline at end of file
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