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
1094ea89
Commit
1094ea89
authored
Nov 24, 2017
by
技术部-任文超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
锁定时长调整为30分钟
parent
92d23e69
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
34 deletions
+60
-34
Constants.java
src/main/java/cn/quantgroup/xyqb/Constants.java
+8
-6
UserController.java
...ntgroup/xyqb/controller/internal/user/UserController.java
+52
-28
No files found.
src/main/java/cn/quantgroup/xyqb/Constants.java
View file @
1094ea89
...
@@ -35,15 +35,17 @@ public interface Constants {
...
@@ -35,15 +35,17 @@ public interface Constants {
String
REDIS_VOICE_DEVICE_COUNT
=
"Voice_Device_verification_code_count:"
;
String
REDIS_VOICE_DEVICE_COUNT
=
"Voice_Device_verification_code_count:"
;
String
REDIS_VERIFICATION_COUNT
=
"verification_code_count:"
;
String
REDIS_VERIFICATION_COUNT
=
"verification_code_count:"
;
final
Long
Image_Need_Count
=
3L
;
Long
Image_Need_Count
=
3L
;
String
REDIS_PASSWORD_ERROR_COUNT
=
"password_error_count:"
;
String
REDIS_PASSWORD_ERROR_COUNT
=
"password_error_count:"
;
String
REDIS_PASSWORD_ERROR_COUNT_FOR_IPV4
=
"password_error_count_4_ipv4:"
;
String
REDIS_PASSWORD_ERROR_COUNT_FOR_IPV4
=
"password_error_count_4_ipv4:"
;
String
IPV4_LOCK
=
"lock_ipv4:"
;
String
IPV4_LOCK
=
"lock_ipv4:"
;
final
Long
IPV4_LOCK_MINUTES
=
6
*
60L
;
Long
IPV4_LOCK_MINUTES
=
30L
;
final
Long
IPV4_COUNT_MINUTES
=
1L
;
Long
IPV4_COUNT_MINUTES
=
1L
;
final
Long
IPV4_LOCK_ON_COUNTS
=
200L
;
Long
IPV4_LOCK_ON_COUNTS
=
200L
;
final
int
DANGEROUS_TIME_START
=
22
;
int
DANGEROUS_TIME_START
=
22
;
final
int
DANGEROUS_TIME_END
=
6
;
int
DANGEROUS_TIME_END
=
6
;
String
CLEAR_LOCK_FOR_IPV4
=
"x-clear-lock-11241842-y"
;
String
CLEAR_LOCK_FOR_IPV4_KEY
=
"lhp.family.dwy.sjs.yym.cxy.cpg"
;
/**
/**
* redis中token的key值前缀
* redis中token的key值前缀
*/
*/
...
...
src/main/java/cn/quantgroup/xyqb/controller/internal/user/UserController.java
View file @
1094ea89
...
@@ -23,6 +23,7 @@ import cn.quantgroup.xyqb.util.DateUtils;
...
@@ -23,6 +23,7 @@ import cn.quantgroup.xyqb.util.DateUtils;
import
cn.quantgroup.xyqb.util.MqUtils
;
import
cn.quantgroup.xyqb.util.MqUtils
;
import
cn.quantgroup.xyqb.util.PasswordUtil
;
import
cn.quantgroup.xyqb.util.PasswordUtil
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
cn.quantgroup.xyqb.util.encrypt.MD5Util
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
...
@@ -36,9 +37,8 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -36,9 +37,8 @@ import org.springframework.web.bind.annotation.RestController;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.UnsupportedEncodingException
;
import
java.io.UnsupportedEncodingException
;
import
java.util.HashMap
;
import
java.nio.charset.Charset
;
import
java.util.Map
;
import
java.util.*
;
import
java.util.Random
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
/**
/**
...
@@ -50,7 +50,6 @@ public class UserController implements IBaseController {
...
@@ -50,7 +50,6 @@ public class UserController implements IBaseController {
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
UserController
.
class
);
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
UserController
.
class
);
private
final
String
pwdSalt
=
"_lkb"
;
private
final
String
pwdSalt
=
"_lkb"
;
@Autowired
@Autowired
...
@@ -95,24 +94,54 @@ public class UserController implements IBaseController {
...
@@ -95,24 +94,54 @@ public class UserController implements IBaseController {
return
loginWithHttpBasic
(
channelId
,
appChannel
,
createdFrom
,
merchant
,
request
,
openId
,
dimension
);
return
loginWithHttpBasic
(
channelId
,
appChannel
,
createdFrom
,
merchant
,
request
,
openId
,
dimension
);
}
}
}
}
//@LogHttpCaller
//@RequestMapping("/login2")
/**
//public JsonResult login2(
* 解锁特定IP
// @RequestParam(required = false, defaultValue = "1") Long channelId, String appChannel,
* @param ip - 目标IP
// @RequestParam(required = false, defaultValue = "1") Long createdFrom,
* @param act - 操作标记,true-lock,false-unlock
// @RequestParam(required = false, defaultValue = "") String userId, HttpServletRequest request, @RequestParam(required = false) String openId,@RequestParam(required = false) String dimension) {
* @param key - 密令
//
* @param request
// if (!StringUtils.isEmpty(userId) && userId.length() > 10) {
* @return
//
*/
// return loginWithUserId(channelId, appChannel, createdFrom, userId, null, dimension);
@RequestMapping
(
"/lock_ipv4"
)
// } else {
public
JsonResult
clearLockForIpv4
(
@RequestParam
(
required
=
true
)
String
ip
,
// return loginWithHttpBasic(channelId, appChannel, createdFrom, null, request, null,dimension);
@RequestParam
(
required
=
false
)
String
act
,
// }
@RequestParam
(
required
=
true
)
String
key
,
//}
HttpServletRequest
request
)
{
if
(!
ValidationUtil
.
validateIpv4
(
ip
)
||
StringUtils
.
isBlank
(
act
)
||
StringUtils
.
isBlank
(
key
)){
@RequestMapping
(
"/test"
)
LOGGER
.
info
(
"Fail to clear_or_lock ip:{}"
,
ip
);
public
JsonResult
test
()
{
return
JsonResult
.
buildErrorStateResult
(
"Are you a robot monkey?(^_^)"
,
null
);
return
JsonResult
.
buildSuccessResult
(
""
,
getCurrentUserFromRedis
());
}
// 操作标记
boolean
lock
=
Objects
.
equals
(
Boolean
.
TRUE
.
toString
(),
act
);
// 解析密令
String
header_key
=
request
.
getHeader
(
Constants
.
CLEAR_LOCK_FOR_IPV4
);
byte
[]
buf
=
Base64
.
decodeBase64
(
header_key
);
header_key
=
new
String
(
buf
,
Charset
.
forName
(
"UTF-8"
));
boolean
valid
=
isValid
(
header_key
,
lock
);
if
(
valid
){
String
lockIpv4Key
=
getLockIpv4Key
(
ip
);
stringRedisTemplate
.
delete
(
lockIpv4Key
);
LOGGER
.
info
(
"Clear_or_lock ip Success:{}"
,
ip
);
return
JsonResult
.
buildSuccessResult
(
"Success"
,
null
);
}
LOGGER
.
info
(
"Fail to clear_or_lock ip:{}"
,
ip
);
return
JsonResult
.
buildErrorStateResult
(
"Are you a robot monkey?(^_^)"
,
null
);
}
/**
* 验证密令
* 私钥 + 操作 + 时
* @param key - Md5密令
* @param lock - true or false
* @return
*/
private
boolean
isValid
(
String
key
,
boolean
lock
)
{
Calendar
today
=
Calendar
.
getInstance
();
int
hour_24
=
today
.
get
(
Calendar
.
HOUR_OF_DAY
);
StringBuilder
_key
=
new
StringBuilder
();
_key
.
append
(
Constants
.
CLEAR_LOCK_FOR_IPV4_KEY
).
append
(
lock
).
append
(
hour_24
);
return
Objects
.
equals
(
key
,
MD5Util
.
build
(
_key
.
toString
()));
}
}
@RequestMapping
(
"/login/fast"
)
@RequestMapping
(
"/login/fast"
)
...
@@ -186,12 +215,7 @@ public class UserController implements IBaseController {
...
@@ -186,12 +215,7 @@ public class UserController implements IBaseController {
}
}
credential
=
credential
.
substring
(
verificationHeader
.
length
(),
credential
.
length
());
credential
=
credential
.
substring
(
verificationHeader
.
length
(),
credential
.
length
());
byte
[]
buf
=
Base64
.
decodeBase64
(
credential
);
byte
[]
buf
=
Base64
.
decodeBase64
(
credential
);
try
{
credential
=
new
String
(
buf
,
Charset
.
forName
(
"UTF-8"
));
credential
=
new
String
(
buf
,
"UTF-8"
);
}
catch
(
UnsupportedEncodingException
e
)
{
LOGGER
.
error
(
"不支持的编码."
);
result
.
put
(
"fail"
,
JsonResult
.
buildErrorStateResult
(
"登录失败"
,
null
));
}
String
[]
credentialArr
=
credential
.
split
(
":"
);
String
[]
credentialArr
=
credential
.
split
(
":"
);
if
(
credentialArr
.
length
!=
2
)
{
if
(
credentialArr
.
length
!=
2
)
{
result
.
put
(
"fail"
,
JsonResult
.
buildErrorStateResult
(
"登录失败"
,
null
));
result
.
put
(
"fail"
,
JsonResult
.
buildErrorStateResult
(
"登录失败"
,
null
));
...
...
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