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
551d15f4
Commit
551d15f4
authored
Dec 15, 2017
by
技术部-任文超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
支持测试环境白名单192.168.0.0/16:-Dtest=true
parent
612094d7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
12 deletions
+17
-12
LockIpv4Controller.java
...oup/xyqb/controller/external/lock/LockIpv4Controller.java
+11
-8
IPUtil.java
src/main/java/cn/quantgroup/xyqb/util/IPUtil.java
+6
-4
No files found.
src/main/java/cn/quantgroup/xyqb/controller/external/lock/LockIpv4Controller.java
View file @
551d15f4
...
...
@@ -30,6 +30,7 @@ import java.util.concurrent.TimeUnit;
@RequestMapping
(
"/lock"
)
public
class
LockIpv4Controller
implements
IBaseController
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
LockIpv4Controller
.
class
);
private
static
final
String
WORD
=
"Are you a robot monkey?(^_^)"
;
@Autowired
@Qualifier
(
"stringRedisTemplate"
)
private
RedisTemplate
<
String
,
String
>
redisTemplate
;
...
...
@@ -43,16 +44,18 @@ public class LockIpv4Controller implements IBaseController {
*/
@RequestMapping
(
"/key"
)
public
JsonResult
key
(
@RequestParam
(
required
=
false
)
String
act
,
HttpServletRequest
request
)
{
//系统环境
String
jvmTest
=
Boolean
.
valueOf
(
System
.
getProperty
(
"test"
)).
toString
();
if
(
Objects
.
equals
(
Boolean
.
TRUE
.
toString
(),
act
)
||
Objects
.
equals
(
Boolean
.
FALSE
.
toString
(),
act
)){
// 操作标记
boolean
lock
=
Objects
.
equals
(
Boolean
.
TRUE
.
toString
(),
act
);
String
header_key
=
request
.
getHeader
(
Constants
.
IPV4_LOCK
.
replace
(
":"
,
""
));
if
(
Objects
.
equals
(
Constants
.
CLEAR_LOCK_FOR_IPV4
,
header_key
)){
String
md5Key
=
ValidationUtil
.
getMd5Key
(
lock
);
return
JsonResult
.
buildErrorStateResult
(
"Are you a robot monkey?(^_^)"
,
md5Key
);
return
JsonResult
.
buildErrorStateResult
(
WORD
.
concat
(
jvmTest
)
,
md5Key
);
}
}
return
JsonResult
.
buildErrorStateResult
(
"Are you a robot monkey?(^_^)"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
WORD
.
concat
(
jvmTest
)
,
null
);
}
/**
...
...
@@ -70,7 +73,7 @@ public class LockIpv4Controller implements IBaseController {
HttpServletRequest
request
)
{
if
(!
ValidationUtil
.
validateIpv4
(
ip
)
||
StringUtils
.
isBlank
(
act
)
||
StringUtils
.
isBlank
(
key
)){
LOGGER
.
info
(
"Lock_ipv4: fail to clear_or_lock ip:{}"
,
ip
);
return
JsonResult
.
buildErrorStateResult
(
"Are you a robot monkey?(^_^)"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
WORD
,
null
);
}
if
(
Objects
.
equals
(
Boolean
.
TRUE
.
toString
(),
act
)
||
Objects
.
equals
(
Boolean
.
FALSE
.
toString
(),
act
)){
// 操作标记
...
...
@@ -82,7 +85,7 @@ public class LockIpv4Controller implements IBaseController {
}
}
LOGGER
.
info
(
"Lock_ipv4: fail to clear_or_lock ip:{}"
,
ip
);
return
JsonResult
.
buildErrorStateResult
(
"Are you a robot monkey?(^_^)"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
WORD
,
null
);
}
/**
...
...
@@ -131,7 +134,7 @@ public class LockIpv4Controller implements IBaseController {
HttpServletRequest
request
)
{
if
(!
ValidationUtil
.
validateIpv4
(
ip
)
||
StringUtils
.
isBlank
(
key
)
||
StringUtils
.
isBlank
(
act
)
||
StringUtils
.
isBlank
(
type
)){
LOGGER
.
info
(
"Lock_ipv4: fail to config hit list for ip:{}"
,
ip
);
return
JsonResult
.
buildErrorStateResult
(
"Are you a robot monkey?(^_^)"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
WORD
,
null
);
}
boolean
actOk
=
Objects
.
equals
(
Boolean
.
TRUE
.
toString
(),
act
)
||
Objects
.
equals
(
Boolean
.
FALSE
.
toString
(),
act
);
boolean
typeOk
=
Objects
.
equals
(
Boolean
.
TRUE
.
toString
(),
type
)
||
Objects
.
equals
(
Boolean
.
FALSE
.
toString
(),
type
);
...
...
@@ -144,7 +147,7 @@ public class LockIpv4Controller implements IBaseController {
return
JsonResult
.
buildSuccessResult
(
"Success"
,
null
);
}
LOGGER
.
info
(
"Lock_ipv4: fail to config hit list for ip:{}"
,
ip
);
return
JsonResult
.
buildErrorStateResult
(
"Are you a robot monkey?(^_^)"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
WORD
,
null
);
}
/**
...
...
@@ -194,7 +197,7 @@ public class LockIpv4Controller implements IBaseController {
HttpServletRequest
request
)
{
if
(
StringUtils
.
isBlank
(
key
)
||
StringUtils
.
isBlank
(
act
)
||
!
StringUtils
.
isNumeric
(
counts
)
||
!
StringUtils
.
isNumeric
(
minutes
)){
LOGGER
.
info
(
"Lock_ipv4: fail to config noun"
);
return
JsonResult
.
buildErrorStateResult
(
"Are you a robot monkey?(^_^)"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
WORD
,
null
);
}
boolean
actOk
=
Objects
.
equals
(
Boolean
.
TRUE
.
toString
(),
act
)
||
Objects
.
equals
(
Boolean
.
FALSE
.
toString
(),
act
);
boolean
valid
=
actOk
&&
ValidationUtil
.
isValid
(
key
,
Objects
.
equals
(
Boolean
.
TRUE
.
toString
(),
act
));
...
...
@@ -211,7 +214,7 @@ public class LockIpv4Controller implements IBaseController {
}
}
LOGGER
.
info
(
"Lock_ipv4: fail to config noun"
);
return
JsonResult
.
buildErrorStateResult
(
"Are you a robot monkey?(^_^)"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
WORD
,
null
);
}
/**
...
...
src/main/java/cn/quantgroup/xyqb/util/IPUtil.java
View file @
551d15f4
...
...
@@ -5,10 +5,7 @@ import org.apache.commons.lang3.StringUtils;
import
org.slf4j.Logger
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Objects
;
import
java.util.Set
;
import
java.util.*
;
/**
* IP地址工具类
...
...
@@ -31,6 +28,11 @@ public class IPUtil {
static
{
String
[]
ips
=
{
"172.16."
,
"172.20."
,
"172.30."
,
"192.168.3."
,
"192.168.4."
};
WHITE_ADDRESS
.
addAll
(
Arrays
.
asList
(
ips
));
//系统环境
String
jvmTest
=
System
.
getProperty
(
"test"
);
if
(
Boolean
.
valueOf
(
jvmTest
)){
WHITE_ADDRESS
.
add
(
"192.168."
);
}
}
/**
...
...
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