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
08f2d3ae
Commit
08f2d3ae
authored
Nov 24, 2017
by
技术部-任文超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完成加锁/解锁/秘钥生成工具类
parent
37533248
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
25 deletions
+46
-25
UserController.java
...ntgroup/xyqb/controller/internal/user/UserController.java
+31
-25
ValidationUtil.java
src/main/java/cn/quantgroup/xyqb/util/ValidationUtil.java
+15
-0
No files found.
src/main/java/cn/quantgroup/xyqb/controller/internal/user/UserController.java
View file @
08f2d3ae
...
@@ -76,23 +76,9 @@ public class UserController implements IBaseController {
...
@@ -76,23 +76,9 @@ public class UserController implements IBaseController {
'l'
,
'm'
,
'n'
,
'o'
,
'p'
,
'q'
,
'r'
,
's'
,
't'
,
'u'
,
'v'
,
'w'
,
'l'
,
'm'
,
'n'
,
'o'
,
'p'
,
'q'
,
'r'
,
's'
,
't'
,
'u'
,
'v'
,
'w'
,
'x'
,
'y'
,
'z'
,
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
};
'x'
,
'y'
,
'z'
,
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
};
@PasswordFineteValidator
@RequestMapping
(
"/test"
)
@RequestMapping
(
"/login"
)
public
JsonResult
test
()
{
public
JsonResult
login
(
return
JsonResult
.
buildSuccessResult
(
""
,
getCurrentUserFromRedis
());
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
)
Long
channelId
,
String
appChannel
,
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
)
Long
createdFrom
,
@RequestParam
(
required
=
false
,
defaultValue
=
""
)
String
userId
,
@RequestParam
(
required
=
false
,
defaultValue
=
"xyqb"
)
String
key
,
HttpServletRequest
request
,
String
openId
,
@RequestParam
(
required
=
false
)
String
dimension
)
{
LOGGER
.
info
(
"user/login,请求参数channelId:{},appChannel:{},createdFrom:{},userId:{},key:{},openId:{},dimension:{},"
,
channelId
,
appChannel
,
createdFrom
,
userId
,
key
,
openId
,
dimension
);
Merchant
merchant
=
merchantService
.
findMerchantByName
(
key
);
if
(
merchant
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"未知的连接"
,
null
);
}
if
(!
StringUtils
.
isEmpty
(
userId
)
&&
userId
.
length
()
>
10
)
{
return
loginWithUserId
(
channelId
,
appChannel
,
createdFrom
,
userId
,
merchant
,
dimension
);
}
else
{
return
loginWithHttpBasic
(
channelId
,
appChannel
,
createdFrom
,
merchant
,
request
,
openId
,
dimension
);
}
}
}
/**
/**
...
@@ -104,7 +90,7 @@ public class UserController implements IBaseController {
...
@@ -104,7 +90,7 @@ public class UserController implements IBaseController {
* @return
* @return
*/
*/
@RequestMapping
(
"/lock_ipv4"
)
@RequestMapping
(
"/lock_ipv4"
)
public
JsonResult
clear
LockFor
Ipv4
(
@RequestParam
(
required
=
true
)
String
ip
,
public
JsonResult
clear
OrLock
Ipv4
(
@RequestParam
(
required
=
true
)
String
ip
,
@RequestParam
(
required
=
false
)
String
act
,
@RequestParam
(
required
=
false
)
String
act
,
@RequestParam
(
required
=
true
)
String
key
,
@RequestParam
(
required
=
true
)
String
key
,
HttpServletRequest
request
)
{
HttpServletRequest
request
)
{
...
@@ -114,21 +100,41 @@ public class UserController implements IBaseController {
...
@@ -114,21 +100,41 @@ public class UserController implements IBaseController {
}
}
// 操作标记
// 操作标记
boolean
lock
=
Objects
.
equals
(
Boolean
.
TRUE
.
toString
(),
act
);
boolean
lock
=
Objects
.
equals
(
Boolean
.
TRUE
.
toString
(),
act
);
// 解析密令
boolean
valid
=
ValidationUtil
.
isValid
(
key
,
lock
);
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
=
ValidationUtil
.
isValid
(
header_key
,
lock
);
if
(
valid
){
if
(
valid
){
String
lockIpv4Key
=
getLockIpv4Key
(
ip
);
String
lockIpv4Key
=
getLockIpv4Key
(
ip
);
stringRedisTemplate
.
delete
(
lockIpv4Key
);
if
(
lock
){
LOGGER
.
info
(
"Clear_or_lock ip Success:{}"
,
ip
);
stringRedisTemplate
.
opsForValue
().
set
(
lockIpv4Key
,
Boolean
.
TRUE
.
toString
(),
Constants
.
IPV4_LOCK_MINUTES
,
TimeUnit
.
MINUTES
);
LOGGER
.
info
(
"Locked ip access:{}, error overstep {} times in {} minutes, do lock {} minutes"
,
ip
,
Constants
.
IPV4_LOCK_ON_COUNTS
,
Constants
.
IPV4_COUNT_MINUTES
,
Constants
.
IPV4_LOCK_MINUTES
);
}
else
{
stringRedisTemplate
.
delete
(
lockIpv4Key
);
LOGGER
.
info
(
"Clear_or_lock ip Success:{}"
,
ip
);
}
return
JsonResult
.
buildSuccessResult
(
"Success"
,
null
);
return
JsonResult
.
buildSuccessResult
(
"Success"
,
null
);
}
}
LOGGER
.
info
(
"Fail to clear_or_lock ip:{}"
,
ip
);
LOGGER
.
info
(
"Fail to clear_or_lock ip:{}"
,
ip
);
return
JsonResult
.
buildErrorStateResult
(
"Are you a robot monkey?(^_^)"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"Are you a robot monkey?(^_^)"
,
null
);
}
}
@PasswordFineteValidator
@RequestMapping
(
"/login"
)
public
JsonResult
login
(
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
)
Long
channelId
,
String
appChannel
,
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
)
Long
createdFrom
,
@RequestParam
(
required
=
false
,
defaultValue
=
""
)
String
userId
,
@RequestParam
(
required
=
false
,
defaultValue
=
"xyqb"
)
String
key
,
HttpServletRequest
request
,
String
openId
,
@RequestParam
(
required
=
false
)
String
dimension
)
{
LOGGER
.
info
(
"user/login,请求参数channelId:{},appChannel:{},createdFrom:{},userId:{},key:{},openId:{},dimension:{},"
,
channelId
,
appChannel
,
createdFrom
,
userId
,
key
,
openId
,
dimension
);
Merchant
merchant
=
merchantService
.
findMerchantByName
(
key
);
if
(
merchant
==
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"未知的连接"
,
null
);
}
if
(!
StringUtils
.
isEmpty
(
userId
)
&&
userId
.
length
()
>
10
)
{
return
loginWithUserId
(
channelId
,
appChannel
,
createdFrom
,
userId
,
merchant
,
dimension
);
}
else
{
return
loginWithHttpBasic
(
channelId
,
appChannel
,
createdFrom
,
merchant
,
request
,
openId
,
dimension
);
}
}
@RequestMapping
(
"/login/fast"
)
@RequestMapping
(
"/login/fast"
)
public
JsonResult
loginFast
(
public
JsonResult
loginFast
(
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
)
Long
channelId
,
String
appChannel
,
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
)
Long
channelId
,
String
appChannel
,
...
...
src/main/java/cn/quantgroup/xyqb/util/ValidationUtil.java
View file @
08f2d3ae
...
@@ -73,6 +73,21 @@ public class ValidationUtil {
...
@@ -73,6 +73,21 @@ public class ValidationUtil {
return
Objects
.
equals
(
key
,
MD5Util
.
build
(
_key
.
toString
()));
return
Objects
.
equals
(
key
,
MD5Util
.
build
(
_key
.
toString
()));
}
}
/**
* 计算密令
* 私钥 + 操作 + 时
* @param key - Md5密令
* @param lock - true or false
* @return 加密后的Md5
*/
public
static
String
getMd5Key
(
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
MD5Util
.
build
(
_key
.
toString
());
}
public
static
boolean
isAtDangerousTime
()
{
public
static
boolean
isAtDangerousTime
()
{
Calendar
now
=
Calendar
.
getInstance
();
Calendar
now
=
Calendar
.
getInstance
();
int
hour
=
now
.
get
(
Calendar
.
HOUR_OF_DAY
);
int
hour
=
now
.
get
(
Calendar
.
HOUR_OF_DAY
);
...
...
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