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
76d966df
Commit
76d966df
authored
Nov 08, 2017
by
技术部-任文超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复账密登录bug
parent
a06ab5c6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
7 deletions
+58
-7
CaptchaFiniteValidateAdvisor.java
...oup/xyqb/aspect/captcha/CaptchaFiniteValidateAdvisor.java
+58
-7
No files found.
src/main/java/cn/quantgroup/xyqb/aspect/captcha/CaptchaFiniteValidateAdvisor.java
View file @
76d966df
...
@@ -4,7 +4,9 @@ package cn.quantgroup.xyqb.aspect.captcha;
...
@@ -4,7 +4,9 @@ package cn.quantgroup.xyqb.aspect.captcha;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.thirdparty.jcaptcha.AbstractManageableImageCaptchaService
;
import
cn.quantgroup.xyqb.thirdparty.jcaptcha.AbstractManageableImageCaptchaService
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
com.octo.captcha.service.CaptchaServiceException
;
import
com.octo.captcha.service.CaptchaServiceException
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Around
;
...
@@ -21,9 +23,9 @@ import org.springframework.web.context.request.RequestContextHolder;
...
@@ -21,9 +23,9 @@ import org.springframework.web.context.request.RequestContextHolder;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.UnsupportedEncodingException
;
import
java.nio.charset.Charset
;
import
java.nio.charset.Charset
;
import
java.util.Optional
;
import
java.util.*
;
import
java.util.UUID
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
/**
/**
...
@@ -79,13 +81,21 @@ public class CaptchaFiniteValidateAdvisor {
...
@@ -79,13 +81,21 @@ public class CaptchaFiniteValidateAdvisor {
@Around
(
"needCaptchaFiniteValidate()"
)
@Around
(
"needCaptchaFiniteValidate()"
)
private
Object
doCapchaValidate
(
ProceedingJoinPoint
pjp
)
throws
Throwable
{
private
Object
doCapchaValidate
(
ProceedingJoinPoint
pjp
)
throws
Throwable
{
HttpServletRequest
request
=
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
();
HttpServletRequest
request
=
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
();
Map
<
String
,
String
>
phonePasswordMap
=
getHeaderParam
(
request
);
if
(
phonePasswordMap
==
null
||
phonePasswordMap
.
isEmpty
()){
return
false
;
}
// 当前用户手机号
String
phoneNo
=
phonePasswordMap
.
get
(
"phoneNo"
);
Long
countErrorByPhone
=
getCount
(
phoneNo
);
if
(
countErrorByPhone
==
null
){
return
JsonResult
.
buildErrorStateResult
(
"用户名或密码不正确"
,
null
);
}
if
(
countErrorByPhone
>
Constants
.
Image_Need_Count
)
{
String
registerFrom
=
Optional
.
ofNullable
(
request
.
getParameter
(
"registerFrom"
)).
orElse
(
""
);
String
registerFrom
=
Optional
.
ofNullable
(
request
.
getParameter
(
"registerFrom"
)).
orElse
(
""
);
String
captchaId
=
Optional
.
ofNullable
(
request
.
getParameter
(
"captchaId"
)).
orElse
(
""
);
String
captchaId
=
Optional
.
ofNullable
(
request
.
getParameter
(
"captchaId"
)).
orElse
(
""
);
Object
captchaValue
=
request
.
getParameter
(
"captchaValue"
);
Object
captchaValue
=
request
.
getParameter
(
"captchaValue"
);
String
phoneNo
=
request
.
getParameter
(
"phoneNo"
);
String
deviceId
=
Optional
.
ofNullable
(
request
.
getParameter
(
"deviceId"
)).
orElse
(
""
);
String
deviceId
=
Optional
.
ofNullable
(
request
.
getParameter
(
"deviceId"
)).
orElse
(
""
);
Long
countErrorByPhone
=
getCount
(
phoneNo
);
if
(
countErrorByPhone
>
Constants
.
Image_Need_Count
)
{
if
(
shouldSkipCaptchaValidate
(
registerFrom
,
captchaId
,
captchaValue
))
{
if
(
shouldSkipCaptchaValidate
(
registerFrom
,
captchaId
,
captchaValue
))
{
LOGGER
.
info
(
"使用超级图形验证码校验, registerFrom={}, clientIp={}"
,
registerFrom
,
request
.
getRemoteAddr
());
LOGGER
.
info
(
"使用超级图形验证码校验, registerFrom={}, clientIp={}"
,
registerFrom
,
request
.
getRemoteAddr
());
return
pjp
.
proceed
();
return
pjp
.
proceed
();
...
@@ -121,6 +131,9 @@ public class CaptchaFiniteValidateAdvisor {
...
@@ -121,6 +131,9 @@ public class CaptchaFiniteValidateAdvisor {
// 获取该账号密码错误计数器
// 获取该账号密码错误计数器
private
Long
getCount
(
String
phoneNo
)
{
private
Long
getCount
(
String
phoneNo
)
{
String
key
=
getKey
(
phoneNo
);
String
key
=
getKey
(
phoneNo
);
if
(
StringUtils
.
isBlank
(
key
))
{
return
null
;
}
String
countString
=
redisTemplate
.
opsForValue
().
get
(
key
);
String
countString
=
redisTemplate
.
opsForValue
().
get
(
key
);
if
(
StringUtils
.
isBlank
(
countString
))
{
if
(
StringUtils
.
isBlank
(
countString
))
{
return
0L
;
return
0L
;
...
@@ -135,4 +148,42 @@ public class CaptchaFiniteValidateAdvisor {
...
@@ -135,4 +148,42 @@ public class CaptchaFiniteValidateAdvisor {
return
Constants
.
REDIS_PASSWORD_ERROR_COUNT
+
phoneNo
;
return
Constants
.
REDIS_PASSWORD_ERROR_COUNT
+
phoneNo
;
}
}
/**
* 单次令牌参数解析
*
* @param request 当前请求,其首部行必须包含形如【SingleToken 13461067662:0123456789abcdef】的UTF-8编码的Base64加密参数
* @return 令牌参数Map 或 null
*/
private
Map
<
String
,
String
>
getHeaderParam
(
HttpServletRequest
request
)
{
String
verificationHeader
=
"Basic "
;
String
credential
=
request
.
getHeader
(
"authorization"
);
if
(
StringUtils
.
isBlank
(
credential
)
||
!
credential
.
startsWith
(
verificationHeader
))
{
LOGGER
.
info
(
"参数无效, credential:{}"
,
credential
);
return
null
;
}
credential
=
credential
.
substring
(
verificationHeader
.
length
(),
credential
.
length
());
byte
[]
buf
=
Base64
.
decodeBase64
(
credential
);
credential
=
new
String
(
buf
,
Charset
.
forName
(
"UTF-8"
));
String
[]
credentialArr
=
credential
.
split
(
":"
);
boolean
headerParamValid
=
credentialArr
.
length
==
2
;
if
(!
headerParamValid
)
{
LOGGER
.
info
(
"参数无效, credential:{}"
,
credential
);
return
null
;
}
// 当前用户手机号
String
phoneNo
=
credentialArr
[
0
];
// 当前请求的SingleToken
String
password
=
credentialArr
[
1
];
headerParamValid
=
headerParamValid
&&
ValidationUtil
.
validatePhoneNo
(
phoneNo
)
&&
StringUtils
.
isNotBlank
(
password
);
if
(!
headerParamValid
)
{
LOGGER
.
info
(
"参数无效, credential:{}, phoneNo:{}, password:{}"
,
credential
,
phoneNo
,
password
);
return
null
;
}
LOGGER
.
info
(
"账密登录, phoneNo:{}, password:{}"
,
phoneNo
,
password
);
Map
<
String
,
String
>
phonePasswordMap
=
new
HashMap
<
String
,
String
>(
2
);
phonePasswordMap
.
put
(
"phoneNo"
,
phoneNo
);
phonePasswordMap
.
put
(
"password"
,
password
);
return
phonePasswordMap
;
}
}
}
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