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
523ce5b3
Commit
523ce5b3
authored
Nov 23, 2017
by
技术部-任文超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
补充22~06点的危险时期识别
parent
f232a9aa
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
1 deletion
+30
-1
Constants.java
src/main/java/cn/quantgroup/xyqb/Constants.java
+2
-0
PasswordErrorFiniteValidateAdvisor.java
...qb/aspect/captcha/PasswordErrorFiniteValidateAdvisor.java
+3
-0
UserController.java
...ntgroup/xyqb/controller/internal/user/UserController.java
+7
-0
ValidationUtil.java
src/main/java/cn/quantgroup/xyqb/util/ValidationUtil.java
+18
-1
No files found.
src/main/java/cn/quantgroup/xyqb/Constants.java
View file @
523ce5b3
...
@@ -42,6 +42,8 @@ public interface Constants {
...
@@ -42,6 +42,8 @@ public interface Constants {
final
Long
IPV4_LOCK_MINUTES
=
6
*
60L
;
final
Long
IPV4_LOCK_MINUTES
=
6
*
60L
;
final
Long
IPV4_COUNT_MINUTES
=
1L
;
final
Long
IPV4_COUNT_MINUTES
=
1L
;
final
Long
IPV4_LOCK_ON_COUNTS
=
60L
;
final
Long
IPV4_LOCK_ON_COUNTS
=
60L
;
final
int
DANGEROUS_TIME_START
=
22
;
final
int
DANGEROUS_TIME_END
=
6
;
/**
/**
* redis中token的key值前缀
* redis中token的key值前缀
*/
*/
...
...
src/main/java/cn/quantgroup/xyqb/aspect/captcha/PasswordErrorFiniteValidateAdvisor.java
View file @
523ce5b3
...
@@ -53,6 +53,9 @@ public class PasswordErrorFiniteValidateAdvisor {
...
@@ -53,6 +53,9 @@ public class PasswordErrorFiniteValidateAdvisor {
*/
*/
@Around
(
"passwordErrorFiniteValidate()"
)
@Around
(
"passwordErrorFiniteValidate()"
)
private
Object
doFiniteValidate
(
ProceedingJoinPoint
pjp
)
throws
Throwable
{
private
Object
doFiniteValidate
(
ProceedingJoinPoint
pjp
)
throws
Throwable
{
if
(!
ValidationUtil
.
isAtDangerousTime
()){
return
pjp
.
proceed
();
}
HttpServletRequest
request
=
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
();
HttpServletRequest
request
=
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
();
// 客户端IP
// 客户端IP
String
clientIp
=
getIp
(
request
);
String
clientIp
=
getIp
(
request
);
...
...
src/main/java/cn/quantgroup/xyqb/controller/internal/user/UserController.java
View file @
523ce5b3
...
@@ -515,12 +515,16 @@ public class UserController implements IBaseController {
...
@@ -515,12 +515,16 @@ public class UserController implements IBaseController {
}
}
String
[]
credentialArr
=
bufStr
.
split
(
":"
);
String
[]
credentialArr
=
bufStr
.
split
(
":"
);
if
(
credentialArr
.
length
!=
2
)
{
if
(
credentialArr
.
length
!=
2
)
{
// 向该ipv4添加错误计数器
countErrorByIpv4
();
return
null
;
return
null
;
}
}
String
userName
=
credentialArr
[
0
];
String
userName
=
credentialArr
[
0
];
String
pass
=
credentialArr
[
1
];
String
pass
=
credentialArr
[
1
];
User
user
=
userService
.
findByPhoneWithCache
(
userName
);
User
user
=
userService
.
findByPhoneWithCache
(
userName
);
if
(
user
==
null
||
!
user
.
getEnable
())
{
if
(
user
==
null
||
!
user
.
getEnable
())
{
// 向该ipv4添加错误计数器
countErrorByIpv4
();
return
null
;
return
null
;
}
}
//验证密码
//验证密码
...
@@ -536,6 +540,9 @@ public class UserController implements IBaseController {
...
@@ -536,6 +540,9 @@ public class UserController implements IBaseController {
* 向该ipv4添加错误计数器
* 向该ipv4添加错误计数器
*/
*/
private
void
countErrorByIpv4
()
{
private
void
countErrorByIpv4
()
{
if
(!
ValidationUtil
.
isAtDangerousTime
()){
return
;
}
String
ipv4
=
getIp
();
String
ipv4
=
getIp
();
if
(
StringUtils
.
isNotBlank
(
ipv4
)
&&
!
ValidationUtil
.
validateLocalIpv4
(
ipv4
))
{
if
(
StringUtils
.
isNotBlank
(
ipv4
)
&&
!
ValidationUtil
.
validateLocalIpv4
(
ipv4
))
{
String
ipv4Key
=
getIpKey
(
getIp
());
String
ipv4Key
=
getIpKey
(
getIp
());
...
...
src/main/java/cn/quantgroup/xyqb/util/ValidationUtil.java
View file @
523ce5b3
package
cn
.
quantgroup
.
xyqb
.
util
;
package
cn
.
quantgroup
.
xyqb
.
util
;
import
cn.quantgroup.xyqb.Constants
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
java.util.Calendar
;
import
java.util.regex.Matcher
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
...
@@ -14,7 +16,7 @@ public class ValidationUtil {
...
@@ -14,7 +16,7 @@ public class ValidationUtil {
private
static
String
phoneRegExp
=
"^((13[0-9])|(14[0-9])|(15[0-9])|(17[0-9])|(18[0-9])|(19[0-9]))\\d{8}$"
;
private
static
String
phoneRegExp
=
"^((13[0-9])|(14[0-9])|(15[0-9])|(17[0-9])|(18[0-9])|(19[0-9]))\\d{8}$"
;
private
static
String
chineseNameRegExp
=
"^[\u4e00-\u9fa5]+(\\.|·)?[\u4e00-\u9fa5]+$"
;
private
static
String
chineseNameRegExp
=
"^[\u4e00-\u9fa5]+(\\.|·)?[\u4e00-\u9fa5]+$"
;
private
static
String
ipv4RegExp
=
"^((2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?)\\.){3}(2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?)$"
;
private
static
String
ipv4RegExp
=
"^((2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?)\\.){3}(2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?)$"
;
private
static
String
localIpv4RegExp
=
"^172
(\\.
2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?){3}$"
;
private
static
String
localIpv4RegExp
=
"^172
\\.(
2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?){3}$"
;
private
static
Pattern
phonePattern
=
Pattern
.
compile
(
phoneRegExp
);
private
static
Pattern
phonePattern
=
Pattern
.
compile
(
phoneRegExp
);
private
static
Pattern
chinesePattern
=
Pattern
.
compile
(
chineseNameRegExp
);
private
static
Pattern
chinesePattern
=
Pattern
.
compile
(
chineseNameRegExp
);
...
@@ -54,6 +56,12 @@ public class ValidationUtil {
...
@@ -54,6 +56,12 @@ public class ValidationUtil {
return
matcher
.
find
();
return
matcher
.
find
();
}
}
public
static
boolean
isAtDangerousTime
()
{
Calendar
now
=
Calendar
.
getInstance
();
int
hour
=
now
.
get
(
Calendar
.
HOUR_OF_DAY
);
return
Constants
.
DANGEROUS_TIME_START
<=
hour
||
hour
<
Constants
.
DANGEROUS_TIME_END
;
}
public
static
boolean
validateChannelId
(
Long
channelId
)
{
public
static
boolean
validateChannelId
(
Long
channelId
)
{
return
channelId
==
0L
?
false
:
true
;
return
channelId
==
0L
?
false
:
true
;
}
}
...
@@ -65,4 +73,13 @@ public class ValidationUtil {
...
@@ -65,4 +73,13 @@ public class ValidationUtil {
return
false
;
return
false
;
}
}
public
static
void
main
(
String
[]
args
){
System
.
out
.
println
(
ValidationUtil
.
validateIpv4
(
"49.150.23.2"
));
System
.
out
.
println
(
ValidationUtil
.
validateIpv4
(
"172.16.4.3"
));
System
.
out
.
println
(
ValidationUtil
.
validateIpv4
(
"192.168.8.9"
));
System
.
out
.
println
(
ValidationUtil
.
validateLocalIpv4
(
"49.150.23.2"
));
System
.
out
.
println
(
ValidationUtil
.
validateLocalIpv4
(
"172.16.4.3"
));
System
.
out
.
println
(
ValidationUtil
.
validateLocalIpv4
(
"192.168.8.9"
));
}
}
}
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