Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cc-service
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SuperHive
back-end
cc-service
Commits
1346c2f3
Commit
1346c2f3
authored
Aug 13, 2020
by
huangcb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RestLogFilter/接口鉴权日志输出级别调整为debug
parent
3ca37f01
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
26 deletions
+60
-26
RestLogFilter.java
...va/com/esv/datacenter/cc/common/filter/RestLogFilter.java
+13
-9
AuthFeignClientImpl.java
...r/cc/module/authentication/feign/AuthFeignClientImpl.java
+29
-11
AuthenticationServiceImpl.java
...uthentication/service/impl/AuthenticationServiceImpl.java
+18
-6
No files found.
src/main/java/com/esv/datacenter/cc/common/filter/RestLogFilter.java
View file @
1346c2f3
...
...
@@ -37,16 +37,20 @@ public class RestLogFilter implements Filter {
RestRequestWrapper
requestWrapper
=
new
RestRequestWrapper
((
HttpServletRequest
)
servletRequest
);
RestResponseWrapper
responseWrapper
=
new
RestResponseWrapper
((
HttpServletResponse
)
servletResponse
);
// 日志输出请求体
this
.
logReq
(
requestWrapper
);
if
(
log
.
isDebugEnabled
())
{
// 日志输出请求体
this
.
logReq
(
requestWrapper
);
// 日志输出请求头
this
.
logReqHeader
(
requestWrapper
);
// 日志输出请求头
this
.
logReqHeader
(
requestWrapper
);
}
filterChain
.
doFilter
(
requestWrapper
,
responseWrapper
);
// 日志输出返回体
this
.
logRes
(
responseWrapper
);
if
(
log
.
isDebugEnabled
())
{
// 日志输出返回体
this
.
logRes
(
responseWrapper
);
}
}
/**
...
...
@@ -76,7 +80,7 @@ public class RestLogFilter implements Filter {
}
// 日志输出请求体
log
.
info
(
"[IP={}]收到{}请求,url:{},body:{}"
,
ReqUtils
.
getHttpClientIp
(
requestWrapper
),
method
,
url
,
reqBody
);
log
.
debug
(
"[IP={}]收到{}请求,url:{},body:{}"
,
ReqUtils
.
getHttpClientIp
(
requestWrapper
),
method
,
url
,
reqBody
);
}
/**
...
...
@@ -89,7 +93,7 @@ public class RestLogFilter implements Filter {
String
key
=
(
String
)
headerNames
.
nextElement
();
headerJson
.
put
(
key
,
request
.
getHeader
(
key
));
}
log
.
info
(
"请求头:{}"
,
headerJson
.
toJSONString
());
log
.
debug
(
"请求头:{}"
,
headerJson
.
toJSONString
());
}
/**
...
...
@@ -103,7 +107,7 @@ public class RestLogFilter implements Filter {
}
catch
(
UnsupportedEncodingException
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
}
log
.
info
(
"请求响应:{}"
,
resBody
);
log
.
debug
(
"请求响应:{}"
,
resBody
);
}
}
src/main/java/com/esv/datacenter/cc/module/authentication/feign/AuthFeignClientImpl.java
View file @
1346c2f3
package
com
.
esv
.
datacenter
.
cc
.
module
.
authentication
.
feign
;
import
com.esv.common.response.ECode
;
import
com.esv.common.response.EResponse
;
import
com.esv.datacenter.cc.common.component.JwtAuthComponent
;
import
com.esv.datacenter.cc.common.constants.ApiResponseCode
;
import
com.esv.datacenter.cc.module.account.bo.TokenBO
;
import
com.esv.datacenter.cc.module.apiauth.service.ApiAuthorityService
;
import
com.esv.datacenter.cc.module.authentication.service.AuthenticationService
;
import
com.esv.datacenter.cc.util.RequestUriUtils
;
import
com.esv.common.response.ECode
;
import
com.esv.common.response.EResponse
;
import
com.esv.feign.cc.client.AuthFeignClient
;
import
com.esv.feign.cc.req.WebReqAuthReq
;
import
com.esv.feign.cc.res.WebReqAuthRes
;
...
...
@@ -63,7 +63,9 @@ public class AuthFeignClientImpl implements AuthFeignClient {
}
String
token
=
webReqAuthReq
.
getToken
();
String
menuCode
=
webReqAuthReq
.
getMenuCode
();
log
.
info
(
"系统鉴权开始 -- menuCode:{}, reqUrl:{}, token:{}"
,
menuCode
,
reqUrl
,
token
);
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"系统鉴权开始 -- menuCode:{}, reqUrl:{}, token:{}"
,
menuCode
,
reqUrl
,
token
);
}
WebReqAuthRes
webReqAuthRes
=
new
WebReqAuthRes
();
webReqAuthRes
.
setSystemCode
(
RequestUriUtils
.
getSystemCode
(
reqUrl
));
...
...
@@ -71,25 +73,35 @@ public class AuthFeignClientImpl implements AuthFeignClient {
Map
<
String
,
Object
>
apiMap
=
apiAuthorityService
.
getAllApiMap
();
if
(!
apiMap
.
containsKey
(
reqUrl
))
{
// URL未注册
log
.
info
(
"URL未注册:{}"
,
reqUrl
);
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"URL未注册:{}"
,
reqUrl
);
}
return
EResponse
.
error
(
ApiResponseCode
.
URL_REGISTERED
);
}
// 鉴权类型
int
authType
=
(
int
)
apiMap
.
get
(
reqUrl
);
log
.
info
(
"该接口鉴权类型authType:{}"
,
authType
);
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"该接口鉴权类型authType:{}"
,
authType
);
}
// 接口不需鉴权
if
(
0
==
authType
)
{
log
.
info
(
"该请求不需要鉴权"
);
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"该请求不需要鉴权"
);
}
return
EResponse
.
ok
(
webReqAuthRes
).
message
(
"该请求不需要鉴权"
);
}
// 判断token格式是否正确
if
(
StringUtils
.
isEmpty
(
token
))
{
log
.
info
(
"无效的Token"
);
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"无效的Token"
);
}
return
EResponse
.
error
(
ECode
.
TOKEN_INVALID
);
}
else
{
if
(!
token
.
startsWith
(
"Basic "
))
{
// token无效
log
.
info
(
"Token格式错误"
);
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"Token格式错误"
);
}
return
EResponse
.
error
(
ECode
.
TOKEN_INVALID
);
}
token
=
StringUtils
.
trimToNull
(
token
.
replaceFirst
(
"Basic "
,
""
));
...
...
@@ -97,11 +109,15 @@ public class AuthFeignClientImpl implements AuthFeignClient {
// 解析token
TokenBO
tokenBO
=
jwtAuthComponent
.
parseToken
(
token
);
if
(
null
==
tokenBO
)
{
log
.
info
(
"无效的Token"
);
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"无效的Token"
);
}
return
EResponse
.
error
(
ECode
.
TOKEN_INVALID
);
}
else
if
((
0L
!=
tokenBO
.
getExpireTime
())
&&
(
System
.
currentTimeMillis
()
>
tokenBO
.
getExpireTime
()))
{
log
.
info
(
"Token已过期"
);
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"Token已过期"
);
}
return
EResponse
.
error
(
ECode
.
TOKEN_EXPIRED
);
}
// 拼装返回信息
...
...
@@ -111,7 +127,9 @@ public class AuthFeignClientImpl implements AuthFeignClient {
webReqAuthRes
.
setDepartmentId
(
tokenBO
.
getDepartmentId
());
// 接口只需token, 不需要具体权限
if
(
1
==
authType
)
{
log
.
info
(
"鉴权通过"
);
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"鉴权通过"
);
}
// 设置数据权限
authenticationService
.
setTokenDataPerm
(
tokenBO
,
webReqAuthRes
);
return
EResponse
.
ok
(
webReqAuthRes
);
...
...
src/main/java/com/esv/datacenter/cc/module/authentication/service/impl/AuthenticationServiceImpl.java
View file @
1346c2f3
...
...
@@ -55,9 +55,13 @@ public class AuthenticationServiceImpl implements AuthenticationService {
@Override
public
EResponse
<
WebReqAuthRes
>
access
(
WebReqAuthRes
webReqAuthRes
,
String
menuCode
,
String
url
)
{
Long
userId
=
webReqAuthRes
.
getUserId
();
log
.
info
(
"用户鉴权开始 -- UserId:{}, MenuCode:{}, Url:{}"
,
userId
,
menuCode
,
url
);
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"用户鉴权开始 -- UserId:{}, MenuCode:{}, Url:{}"
,
userId
,
menuCode
,
url
);
}
if
(
userRoleService
.
hasSuperAdminRole
(
userId
))
{
log
.
info
(
"用户拥有超级管理员角色, 数据权限类型:{}"
,
webReqAuthRes
.
getDataPerm
());
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"用户拥有超级管理员角色, 数据权限类型:{}"
,
webReqAuthRes
.
getDataPerm
());
}
return
EResponse
.
ok
(
webReqAuthRes
);
}
...
...
@@ -72,7 +76,9 @@ public class AuthenticationServiceImpl implements AuthenticationService {
Set
<
String
>
userPermSet
=
menuService
.
userPermSet
(
null
,
userId
,
null
);
String
permStr
=
RequestUriUtils
.
getPermsUrl
(
url
);
if
(!
userPermSet
.
contains
(
permStr
))
{
log
.
info
(
"鉴权失败, 用户没有该权限"
);
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"鉴权失败, 用户没有该权限"
);
}
return
EResponse
.
error
(
ApiResponseCode
.
NO_AUTHORITY
);
}
...
...
@@ -94,7 +100,9 @@ public class AuthenticationServiceImpl implements AuthenticationService {
webReqAuthRes
.
setDepartmentChildren
(
departmentChildren
);
}
webReqAuthRes
.
setDataPerm
(
dataPerm
);
log
.
info
(
"鉴权成功, 数据权限类型:{}"
,
dataPerm
);
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"鉴权成功, 数据权限类型:{}"
,
dataPerm
);
}
return
EResponse
.
ok
(
webReqAuthRes
);
}
...
...
@@ -121,7 +129,9 @@ public class AuthenticationServiceImpl implements AuthenticationService {
@Override
public
boolean
isAllowAccess
(
long
userId
,
String
url
)
{
log
.
info
(
"鉴权开始 -- UserId:{}, Url:{}"
,
userId
,
url
);
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"鉴权开始 -- UserId:{}, Url:{}"
,
userId
,
url
);
}
Preconditions
.
checkArgument
(
StringUtils
.
isNotBlank
(
url
));
if
(
userRoleService
.
hasSuperAdminRole
(
userId
))
{
return
true
;
...
...
@@ -145,7 +155,9 @@ public class AuthenticationServiceImpl implements AuthenticationService {
Set
<
String
>
userPermSet
=
menuService
.
userPermSet
(
entity
.
getId
(),
userId
,
null
);
String
permStr
=
RequestUriUtils
.
getPermsUrl
(
url
);
boolean
result
=
userPermSet
.
contains
(
permStr
);
log
.
info
(
"鉴权结果 -- {}"
,
result
);
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"鉴权结果 -- {}"
,
result
);
}
return
result
;
}
...
...
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