Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
hphy
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
向怀芳
hphy
Commits
767a02be
Commit
767a02be
authored
Oct 21, 2022
by
向怀芳
🎱
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1. 代理IP处理02
parent
356ff45a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
255 additions
and
254 deletions
+255
-254
SictTokenEndpoint.java
...cn/sh/stc/sict/cloud/auth/endpoint/SictTokenEndpoint.java
+1
-4
WebUtils.java
.../java/cn/sh/stc/sict/cloud/common/core/util/WebUtils.java
+253
-249
RequestGlobalFilter.java
...sict/cloud/common/gateway/filter/RequestGlobalFilter.java
+1
-1
No files found.
cloud-auth/src/main/java/cn/sh/stc/sict/cloud/auth/endpoint/SictTokenEndpoint.java
View file @
767a02be
...
...
@@ -80,10 +80,7 @@ public class SictTokenEndpoint {
String
tokenValue
=
authHeader
.
replaceAll
(
"(?i)Bearer"
,
""
).
trim
();
OAuth2AccessToken
accessToken
=
tokenStore
.
readAccessToken
(
tokenValue
);
if
(
accessToken
==
null
||
StrUtil
.
isBlank
(
accessToken
.
getValue
()))
{
return
R
.
builder
()
.
code
(
Constant
.
BYTE_NO
)
.
data
(
Boolean
.
FALSE
)
.
msg
(
"退出失败,token 无效"
).
build
();
return
new
R
();
}
OAuth2Authentication
auth2Authentication
=
tokenStore
.
readAuthentication
(
accessToken
);
...
...
cloud-common/cloud-common-core/src/main/java/cn/sh/stc/sict/cloud/common/core/util/WebUtils.java
View file @
767a02be
...
...
@@ -158,7 +158,7 @@ public class WebUtils extends org.springframework.web.util.WebUtils {
return
getIP
(
WebUtils
.
getRequest
());
}
public
String
getSession
()
{
public
String
getSession
()
{
return
WebUtils
.
getSessionId
(
WebUtils
.
getRequest
());
}
...
...
@@ -196,13 +196,17 @@ public class WebUtils extends org.springframework.web.util.WebUtils {
public
String
getIP
(
ServerHttpRequest
request
)
{
HttpHeaders
headers
=
request
.
getHeaders
();
String
ip
=
headers
.
getFirst
(
"x-forwarded-for"
);
log
.
error
(
"getIp.ip = {}"
,
ip
);
log
.
error
(
"headers = {}"
,
JSONUtil
.
toJsonStr
(
headers
)
);
if
(
ip
!=
null
&&
ip
.
length
()
!=
0
&&
!
"unknown"
.
equalsIgnoreCase
(
ip
))
{
// 多次反向代理后会有多个ip值,第一个ip才是真实ip
if
(
ip
.
indexOf
(
","
)
!=
-
1
)
{
if
(
"127.0.0.1"
.
equals
(
ip
.
split
(
","
)[
0
]))
{
ip
=
ip
.
split
(
","
)[
1
];
}
else
{
ip
=
ip
.
split
(
","
)[
0
];
}
}
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
headers
.
getFirst
(
"Proxy-Client-IP"
);
}
...
...
@@ -257,13 +261,12 @@ public class WebUtils extends org.springframework.web.util.WebUtils {
}
/**
*
* @param request HttpServletRequest
* tip: 不可使用WebUtils.getRequest()获取
* @param allowSuffix 文件后缀名 多个以","逗号分隔
* @return
*/
public
MultipartFile
getRequestFile
(
@NonNull
HttpServletRequest
request
,
@NonNull
String
allowSuffix
)
{
public
MultipartFile
getRequestFile
(
@NonNull
HttpServletRequest
request
,
@NonNull
String
allowSuffix
)
{
String
errorMsg
=
StrUtil
.
EMPTY
;
String
[]
suffixs
=
allowSuffix
.
split
(
","
);
...
...
@@ -275,26 +278,27 @@ public class WebUtils extends org.springframework.web.util.WebUtils {
file
=
fileEntity
.
getValue
();
String
originalFilename
=
file
.
getOriginalFilename
();
String
suffix
=
originalFilename
.
substring
(
originalFilename
.
lastIndexOf
(
'.'
)
+
1
);
if
(
suffixSet
.
contains
(
suffix
))
{
if
(
suffixSet
.
contains
(
suffix
))
{
break
;
}
errorMsg
=
"文件类型不支持"
;
}
Assert
.
isTrue
(
StrUtil
.
isBlank
(
errorMsg
),
errorMsg
);
Objects
.
requireNonNull
(
file
,
"excel导入 ---------->>>>>>> 未检测到上传文件"
);
Objects
.
requireNonNull
(
file
,
"excel导入 ---------->>>>>>> 未检测到上传文件"
);
return
file
;
}
/**
* 导出excel
*
* @param list 数据
* @param writer
* @param name 文件名
*/
@SneakyThrows
public
void
exportExcel
(
@NonNull
List
list
,
@NonNull
ExcelWriter
writer
,
String
name
)
{
public
void
exportExcel
(
@NonNull
List
list
,
@NonNull
ExcelWriter
writer
,
String
name
)
{
writer
.
setOnlyAlias
(
true
);
HttpServletResponse
response
=
WebUtils
.
getResponse
();
//response为HttpServletResponse对象
...
...
cloud-common/cloud-common-gateway/src/main/java/cn/sh/stc/sict/cloud/common/gateway/filter/RequestGlobalFilter.java
View file @
767a02be
...
...
@@ -65,7 +65,7 @@ public class RequestGlobalFilter implements GlobalFilter, Ordered {
// IP白名单
String
ip
=
WebUtils
.
getIP
(
request
);
//
log.error("RemoteAddress = {}, ip = {}", request.getRemoteAddress(), ip);
log
.
error
(
"RemoteAddress = {}, ip = {}"
,
request
.
getRemoteAddress
(),
ip
);
try
{
if
(
whitIPConfig
.
getLimitFlag
()
&&
!
IPStrUtil
.
matches
(
ip
,
whitIPConfig
.
getWhites
()))
{
ServerHttpResponse
response
=
exchange
.
getResponse
();
...
...
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