Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
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
youjj
cloud-platform
Commits
31866671
Commit
31866671
authored
Aug 06, 2019
by
jiaorz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
网关日志限制修改
parent
aa0b9aba
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
35 deletions
+42
-35
AccessGatewayFilter.java
...hub/wxiaoqi/security/gate/filter/AccessGatewayFilter.java
+40
-33
logback.xml
ace-gate/src/main/resources/logback.xml
+2
-2
No files found.
ace-gate/src/main/java/com/github/wxiaoqi/security/gate/filter/AccessGatewayFilter.java
View file @
31866671
...
...
@@ -54,7 +54,7 @@ import java.util.stream.Stream;
*/
@Configuration
@Slf4j
public
class
AccessGatewayFilter
implements
GlobalFilter
{
public
class
AccessGatewayFilter
implements
GlobalFilter
{
@Autowired
@Lazy
private
IUserService
userService
;
...
...
@@ -257,7 +257,7 @@ public class AccessGatewayFilter implements GlobalFilter{
private
boolean
isStartWith
(
String
requestUri
)
{
boolean
flag
=
false
;
for
(
String
s
:
GATE_WAY_UNAUTH
.
split
(
","
))
{
if
(
requestUri
.
contains
(
s
))
{
if
(
requestUri
.
contains
(
s
))
{
return
true
;
}
}
...
...
@@ -286,7 +286,7 @@ public class AccessGatewayFilter implements GlobalFilter{
ServerRequest
serverRequest
=
new
DefaultServerRequest
(
exchange
);
// 如果是json格式,将body内容转化为object or map 都可
if
(
MediaType
.
APPLICATION_JSON
.
isCompatibleWith
(
mediaType
)){
if
(
MediaType
.
APPLICATION_JSON
.
isCompatibleWith
(
mediaType
))
{
Mono
<
Object
>
modifiedBody
=
serverRequest
.
bodyToMono
(
Object
.
class
)
.
flatMap
(
body
->
{
recordLog
(
exchange
.
getRequest
(),
body
);
...
...
@@ -295,7 +295,7 @@ public class AccessGatewayFilter implements GlobalFilter{
}
// 如果是表单请求
else
if
(
MediaType
.
APPLICATION_FORM_URLENCODED
.
isCompatibleWith
(
mediaType
))
{
else
if
(
MediaType
.
APPLICATION_FORM_URLENCODED
.
isCompatibleWith
(
mediaType
))
{
Mono
<
String
>
modifiedBody
=
serverRequest
.
bodyToMono
(
String
.
class
)
// .log("modify_request_mono", Level.INFO)
.
flatMap
(
body
->
{
...
...
@@ -310,13 +310,15 @@ public class AccessGatewayFilter implements GlobalFilter{
// 无法兼容的请求,则不读取body,像Get请求这种
recordLog
(
exchange
.
getRequest
(),
""
);
}
private
void
recordLog
(
ServerHttpRequest
request
,
Object
body
)
{
// 记录要访问的url
if
(!
getNotLogUri
().
contains
(
request
.
getURI
().
getRawPath
()))
{
StringBuilder
builder
=
new
StringBuilder
();
log
.
info
(
"=================请求uri:"
+
request
.
getURI
().
getRawPath
());
// 记录访问的方法
HttpMethod
method
=
request
.
getMethod
();
if
(
null
!=
method
)
{
if
(
null
!=
method
)
{
log
.
info
(
"=================请求方法:"
+
method
.
name
());
}
// 记录头部信息
...
...
@@ -334,12 +336,17 @@ public class AccessGatewayFilter implements GlobalFilter{
for
(
Map
.
Entry
<
String
,
List
<
String
>>
entry
:
queryParams
.
entrySet
())
{
builder
.
append
(
entry
.
getKey
()).
append
(
"="
).
append
(
StringUtils
.
join
(
entry
.
getValue
(),
","
)).
append
(
","
);
}
}
else
{
}
else
{
// 从body中读取参数
builder
.
append
(
body
);
}
log
.
info
(
"=================请求参数:"
+
builder
.
toString
());
}
}
@Value
(
"${logback.ignore-log-path}"
)
String
[]
path
;
public
List
<
String
>
getNotLogUri
()
{
return
Arrays
.
asList
(
path
);
}
}
ace-gate/src/main/resources/logback.xml
View file @
31866671
...
...
@@ -22,7 +22,7 @@
<filter
class=
"com.github.wxiaoqi.security.common.filter.DenyFilter"
></filter>
<rollingPolicy
class=
"ch.qos.logback.core.rolling.TimeBasedRollingPolicy"
>
<FileNamePattern>
${LOG_HOME}/sys.%d{yyyy-MM-dd}.log
</FileNamePattern>
<!--日志文件输出的文件名 -->
<MaxHistory>
30
</MaxHistory>
<!--日志文件保留天数 -->
<MaxHistory>
15
</MaxHistory>
<!--日志文件保留天数 -->
</rollingPolicy>
<encoder
class=
"ch.qos.logback.classic.encoder.PatternLayoutEncoder"
>
<Pattern>
${CONSOLE_LOG_PATTERN}
</Pattern>
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 -->
...
...
@@ -33,7 +33,7 @@
<filter
class=
"com.github.wxiaoqi.security.common.filter.AcceptFilter"
></filter>
<rollingPolicy
class=
"ch.qos.logback.core.rolling.TimeBasedRollingPolicy"
>
<FileNamePattern>
${LOG_HOME}/log.%d{yyyy-MM-dd}.log
</FileNamePattern>
<!--日志文件输出的文件名 -->
<MaxHistory>
30
</MaxHistory>
<!--日志文件保留天数 -->
<MaxHistory>
15
</MaxHistory>
<!--日志文件保留天数 -->
</rollingPolicy>
<encoder
class=
"ch.qos.logback.classic.encoder.PatternLayoutEncoder"
>
<Pattern>
${CONSOLE_LOG_PATTERN}
</Pattern>
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 -->
...
...
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