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
5be2ba6b
Commit
5be2ba6b
authored
Mar 23, 2020
by
xiaoguang.xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
15 天token 有效期
parent
bbe7f477
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
8 deletions
+16
-8
Constants.java
src/main/java/cn/quantgroup/xyqb/Constants.java
+1
-1
UserApiController.java
...roup/xyqb/controller/internal/user/UserApiController.java
+6
-3
ISessionService.java
...a/cn/quantgroup/xyqb/service/session/ISessionService.java
+1
-0
SessionServiceImpl.java
...ntgroup/xyqb/service/session/impl/SessionServiceImpl.java
+8
-4
No files found.
src/main/java/cn/quantgroup/xyqb/Constants.java
View file @
5be2ba6b
...
@@ -172,7 +172,7 @@ public interface Constants {
...
@@ -172,7 +172,7 @@ public interface Constants {
String
USER_SESSION_CACHE
=
"user:session:"
;
String
USER_SESSION_CACHE
=
"user:session:"
;
String
USER_SESSION_ID_CACHE
=
"userid-sessionvalue:cache:"
;
String
USER_SESSION_ID_CACHE
=
"userid-sessionvalue:cache:"
;
String
USER_SESSION_KEY_SET
=
"userid-keys:set:"
;
String
USER_SESSION_KEY_SET
=
"userid-keys:set:"
;
Long
ONE_DAY
=
24
*
60
*
60L
;
Long
SESSION_VALID_TIME
=
15
*
24
*
60
*
60L
;
}
}
interface
UserAvatar
{
interface
UserAvatar
{
...
...
src/main/java/cn/quantgroup/xyqb/controller/internal/user/UserApiController.java
View file @
5be2ba6b
...
@@ -66,8 +66,11 @@ public class UserApiController {
...
@@ -66,8 +66,11 @@ public class UserApiController {
@ApiOperation
(
notes
=
"检查token是否有效,如果有效,可选择是否延续生命期(延续后有效期24Hour)"
,
value
=
"Check token and then prolong session"
,
nickname
=
"checkToken"
)
@ApiOperation
(
notes
=
"检查token是否有效,如果有效,可选择是否延续生命期(延续后有效期24Hour)"
,
value
=
"Check token and then prolong session"
,
nickname
=
"checkToken"
)
@IpValidator
@IpValidator
@RequestMapping
(
value
=
"/valid/{token}"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/valid/{token}"
,
method
=
RequestMethod
.
POST
)
public
JsonResult
checkToken
(
@ApiParam
(
value
=
"sid,session的id"
,
required
=
true
)
@PathVariable
(
"token"
)
String
token
,
public
JsonResult
checkToken
(
@ApiParam
(
value
=
"sid,session的id"
,
required
=
true
)
@ApiParam
(
value
=
"是否延续生命期,可选参数,默认为: false - 不延续"
)
@RequestParam
(
name
=
"prolong"
,
required
=
false
,
defaultValue
=
"false"
)
Boolean
prolong
)
{
@PathVariable
(
"token"
)
String
token
,
@ApiParam
(
value
=
"是否延续生命期,可选参数,默认为: false - 不延续"
)
@RequestParam
(
name
=
"prolong"
,
required
=
false
,
defaultValue
=
"false"
)
Boolean
prolong
,
@RequestParam
(
name
=
"prolongTime"
,
required
=
false
,
defaultValue
=
"86400"
)
Long
prolongTime
)
{
if
(
Objects
.
isNull
(
token
)
||
!
ValidationUtil
.
validateToken
(
token
))
{
if
(
Objects
.
isNull
(
token
)
||
!
ValidationUtil
.
validateToken
(
token
))
{
return
JsonResult
.
buildErrorStateResult
(
"token invalid"
,
token
);
return
JsonResult
.
buildErrorStateResult
(
"token invalid"
,
token
);
}
}
...
@@ -87,7 +90,7 @@ public class UserApiController {
...
@@ -87,7 +90,7 @@ public class UserApiController {
}
else
{
}
else
{
/* 延续session生命期 */
/* 延续session生命期 */
try
{
try
{
sessionService
.
persistSession
(
sessionStruct
.
getSid
(),
sessionStruct
.
getValues
());
sessionService
.
persistSession
(
sessionStruct
.
getSid
(),
sessionStruct
.
getValues
()
,
prolongTime
);
log
.
info
(
"延续token:[{}]生命期,result:[{}]"
,
token
,
true
);
log
.
info
(
"延续token:[{}]生命期,result:[{}]"
,
token
,
true
);
}
finally
{
}
finally
{
XyqbSessionContextHolder
.
releaseSession
();
XyqbSessionContextHolder
.
releaseSession
();
...
...
src/main/java/cn/quantgroup/xyqb/service/session/ISessionService.java
View file @
5be2ba6b
...
@@ -27,6 +27,7 @@ public interface ISessionService {
...
@@ -27,6 +27,7 @@ public interface ISessionService {
SessionStruct
createSessionAndPersist
(
User
user
,
LoginProperties
loginProperties
);
SessionStruct
createSessionAndPersist
(
User
user
,
LoginProperties
loginProperties
);
void
persistSession
(
String
token
,
SessionValue
sessionValue
);
void
persistSession
(
String
token
,
SessionValue
sessionValue
);
void
persistSession
(
String
token
,
SessionValue
sessionValue
,
Long
time
);
void
deleteByUserId
(
long
userId
);
void
deleteByUserId
(
long
userId
);
...
...
src/main/java/cn/quantgroup/xyqb/service/session/impl/SessionServiceImpl.java
View file @
5be2ba6b
...
@@ -136,16 +136,20 @@ public class SessionServiceImpl implements ISessionService {
...
@@ -136,16 +136,20 @@ public class SessionServiceImpl implements ISessionService {
@Override
@Override
@UserBtRegisterFill
@UserBtRegisterFill
public
void
persistSession
(
String
token
,
SessionValue
sessionValue
)
{
public
void
persistSession
(
String
token
,
SessionValue
sessionValue
)
{
persistSession
(
token
,
sessionValue
,
Constants
.
Session
.
SESSION_VALID_TIME
);
}
@Override
public
void
persistSession
(
String
token
,
SessionValue
sessionValue
,
Long
time
)
{
Timestamp
current
=
new
Timestamp
(
System
.
currentTimeMillis
());
Timestamp
current
=
new
Timestamp
(
System
.
currentTimeMillis
());
sessionValue
.
setLastAccessTime
(
current
);
sessionValue
.
setLastAccessTime
(
current
);
String
json
=
JSON
.
toJSONString
(
sessionValue
);
String
json
=
JSON
.
toJSONString
(
sessionValue
);
stringRedisTemplate
.
opsForValue
().
set
(
Constants
.
Session
.
USER_SESSION_CACHE
+
token
,
json
,
stringRedisTemplate
.
opsForValue
().
set
(
Constants
.
Session
.
USER_SESSION_CACHE
+
token
,
json
,
Constants
.
Session
.
ONE_DAY
,
TimeUnit
.
SECONDS
);
time
,
TimeUnit
.
SECONDS
);
String
key
=
generateLoginPropertiesKey
(
sessionValue
.
getUser
().
getId
(),
sessionValue
.
getLoginProperties
());
String
key
=
generateLoginPropertiesKey
(
sessionValue
.
getUser
().
getId
(),
sessionValue
.
getLoginProperties
());
stringRedisTemplate
.
opsForValue
().
set
(
key
,
token
,
Constants
.
Session
.
ONE_DAY
,
TimeUnit
.
SECONDS
);
stringRedisTemplate
.
opsForValue
().
set
(
key
,
token
,
time
,
TimeUnit
.
SECONDS
);
log
.
info
(
"[Session生命期延续],token:{},有效期:[24Hour]"
,
token
);
log
.
info
(
"[Session生命期延续],token:{},有效期:[24Hour]"
,
token
);
setUserIdTokenKeys
(
sessionValue
.
getUser
().
getId
(),
key
);
setUserIdTokenKeys
(
sessionValue
.
getUser
().
getId
(),
key
);
}
}
/**
/**
...
@@ -159,7 +163,7 @@ public class SessionServiceImpl implements ISessionService {
...
@@ -159,7 +163,7 @@ public class SessionServiceImpl implements ISessionService {
String
setKey
=
getUserSessionSetKey
(
userId
);
String
setKey
=
getUserSessionSetKey
(
userId
);
try
{
try
{
stringRedisTemplate
.
opsForSet
().
add
(
setKey
,
key
);
stringRedisTemplate
.
opsForSet
().
add
(
setKey
,
key
);
stringRedisTemplate
.
expire
(
setKey
,
Constants
.
Session
.
ONE_DAY
,
TimeUnit
.
SECONDS
);
stringRedisTemplate
.
expire
(
setKey
,
Constants
.
Session
.
SESSION_VALID_TIME
,
TimeUnit
.
SECONDS
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"存储用户注销件失败,userId:{},Exception:{}"
,
userId
,
e
);
log
.
error
(
"存储用户注销件失败,userId:{},Exception:{}"
,
userId
,
e
);
}
}
...
...
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