Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
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
head_group
xyqb-user2
Commits
ee380f09
Commit
ee380f09
authored
May 10, 2017
by
Java-刘 彧阳
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
对innerapi的访问进行IP限制
parent
9e948f96
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
5 deletions
+11
-5
IPWhiteListInterceptor.java
.../quantgroup/xyqb/interceptors/IPWhiteListInterceptor.java
+11
-5
No files found.
src/main/java/cn/quantgroup/xyqb/interceptors/IPWhiteListInterceptor.java
View file @
ee380f09
package
cn
.
quantgroup
.
xyqb
.
interceptors
;
package
cn
.
quantgroup
.
xyqb
.
interceptors
;
import
cn.quantgroup.xyqb.util.IPUtil
;
import
cn.quantgroup.xyqb.util.IPUtil
;
import
com.google.common.collect.Sets
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -9,6 +10,8 @@ import org.springframework.web.servlet.ModelAndView;
...
@@ -9,6 +10,8 @@ import org.springframework.web.servlet.ModelAndView;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
/**
/**
...
@@ -21,6 +24,8 @@ public class IPWhiteListInterceptor implements HandlerInterceptor {
...
@@ -21,6 +24,8 @@ public class IPWhiteListInterceptor implements HandlerInterceptor {
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
IPWhiteListInterceptor
.
class
);
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
IPWhiteListInterceptor
.
class
);
private
static
final
String
patternStr
=
"172.*"
;
private
static
final
String
patternStr
=
"172.*"
;
private
static
final
String
[]
allowIPs
=
{
"139.198.7.123"
};
private
static
Set
<
String
>
allowIPSet
=
Sets
.
newHashSet
(
allowIPs
);
private
static
final
Pattern
pattern
=
Pattern
.
compile
(
patternStr
);
private
static
final
Pattern
pattern
=
Pattern
.
compile
(
patternStr
);
public
IPWhiteListInterceptor
(
Integer
isDebug
)
{
public
IPWhiteListInterceptor
(
Integer
isDebug
)
{
...
@@ -32,15 +37,16 @@ public class IPWhiteListInterceptor implements HandlerInterceptor {
...
@@ -32,15 +37,16 @@ public class IPWhiteListInterceptor implements HandlerInterceptor {
if
(
isDebug
!=
0
)
return
true
;
if
(
isDebug
!=
0
)
return
true
;
String
remoteIP
=
IPUtil
.
getRemoteIP
(
request
);
String
remoteIP
=
IPUtil
.
getRemoteIP
(
request
);
if
(
StringUtils
.
isNoneBlank
(
remoteIP
)){
if
(
StringUtils
.
isNoneBlank
(
remoteIP
)){
/*boolean isMatch = pattern.matcher(remoteIP).matches();
remoteIP
=
remoteIP
.
trim
();
boolean
isMatch
=
pattern
.
matcher
(
remoteIP
).
matches
();
isMatch
=
Boolean
.
logicalOr
(
isMatch
,
allowIPSet
.
contains
(
remoteIP
));
if
(!
isMatch
){
if
(!
isMatch
){
LOGGER
.
info
(
"非法IP尝试访问,ip:[{}]"
,
remoteIP
);
LOGGER
.
info
(
"非法IP尝试访问,ip:[{}]"
,
remoteIP
);
}
}
return isMatch;*/
return
isMatch
;
LOGGER
.
info
(
"来源IP:[{}]"
,
remoteIP
);
}
}
//
LOGGER.info("未能获取remoteIP");
LOGGER
.
info
(
"未能获取remoteIP"
);
return
tru
e
;
return
fals
e
;
}
}
@Override
@Override
...
...
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