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
f812088c
Commit
f812088c
authored
Jan 11, 2022
by
李健华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
交换token增加过期时间
parent
421551c2
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
9 additions
and
4 deletions
+9
-4
UserController.java
...n/quantgroup/xyqb/controller/external/UserController.java
+2
-1
TokenExchange.java
src/main/java/cn/quantgroup/xyqb/model/TokenExchange.java
+2
-0
SessionStruct.java
.../java/cn/quantgroup/xyqb/model/session/SessionStruct.java
+1
-0
ISessionService.java
...a/cn/quantgroup/xyqb/service/session/ISessionService.java
+1
-1
SessionServiceImpl.java
...ntgroup/xyqb/service/session/impl/SessionServiceImpl.java
+2
-2
XyqbSessionContextHolder.java
.../cn/quantgroup/xyqb/session/XyqbSessionContextHolder.java
+1
-0
No files found.
src/main/java/cn/quantgroup/xyqb/controller/external/UserController.java
View file @
f812088c
...
@@ -531,6 +531,7 @@ public class UserController implements IBaseController {
...
@@ -531,6 +531,7 @@ public class UserController implements IBaseController {
tokenExchange
.
setUserId
(
user
.
getId
());
tokenExchange
.
setUserId
(
user
.
getId
());
tokenExchange
.
setPhoneNo
(
user
.
getPhoneNo
());
tokenExchange
.
setPhoneNo
(
user
.
getPhoneNo
());
tokenExchange
.
setUuid
(
user
.
getUuid
());
tokenExchange
.
setUuid
(
user
.
getUuid
());
tokenExchange
.
setExpire
(
sessionStruct
.
getExpire
());
return
JsonResult
.
buildSuccessResult
(
null
,
tokenExchange
);
return
JsonResult
.
buildSuccessResult
(
null
,
tokenExchange
);
}
}
...
@@ -564,7 +565,7 @@ public class UserController implements IBaseController {
...
@@ -564,7 +565,7 @@ public class UserController implements IBaseController {
// 根据返回值生成token, 返回值包含user:session:token的值
// 根据返回值生成token, 返回值包含user:session:token的值
sessionValue
.
setUser
(
user
);
sessionValue
.
setUser
(
user
);
sessionValue
.
setLoginProperties
(
loginProperties
);
sessionValue
.
setLoginProperties
(
loginProperties
);
sessionService
.
persistSessionExchange
(
token
,
sessionValue
);
sessionService
.
persistSessionExchange
(
token
,
sessionValue
,
tokenExchange
.
getExpire
()
);
}
}
}
}
...
...
src/main/java/cn/quantgroup/xyqb/model/TokenExchange.java
View file @
f812088c
...
@@ -26,4 +26,6 @@ public class TokenExchange implements Serializable {
...
@@ -26,4 +26,6 @@ public class TokenExchange implements Serializable {
private
String
loginProperties
;
private
String
loginProperties
;
private
Long
expire
=
15
*
24
*
60
*
60L
;
}
}
src/main/java/cn/quantgroup/xyqb/model/session/SessionStruct.java
View file @
f812088c
...
@@ -16,6 +16,7 @@ public class SessionStruct implements Serializable {
...
@@ -16,6 +16,7 @@ public class SessionStruct implements Serializable {
private
static
final
long
serialVersionUID
=
-
1L
;
private
static
final
long
serialVersionUID
=
-
1L
;
private
String
sid
;
private
String
sid
;
private
SessionValue
values
;
private
SessionValue
values
;
private
long
expire
;
public
void
setAttribute
(
String
key
,
String
value
)
{
public
void
setAttribute
(
String
key
,
String
value
)
{
if
(
value
==
null
)
{
if
(
value
==
null
)
{
...
...
src/main/java/cn/quantgroup/xyqb/service/session/ISessionService.java
View file @
f812088c
...
@@ -42,5 +42,5 @@ public interface ISessionService {
...
@@ -42,5 +42,5 @@ public interface ISessionService {
*/
*/
void
deleteSession
(
String
token
);
void
deleteSession
(
String
token
);
void
persistSessionExchange
(
String
token
,
SessionValue
sessionValue
);
void
persistSessionExchange
(
String
token
,
SessionValue
sessionValue
,
long
expire
);
}
}
src/main/java/cn/quantgroup/xyqb/service/session/impl/SessionServiceImpl.java
View file @
f812088c
...
@@ -287,14 +287,14 @@ public class SessionServiceImpl implements ISessionService {
...
@@ -287,14 +287,14 @@ public class SessionServiceImpl implements ISessionService {
}
}
@Override
@Override
public
void
persistSessionExchange
(
String
token
,
SessionValue
sessionValue
)
{
public
void
persistSessionExchange
(
String
token
,
SessionValue
sessionValue
,
long
expire
)
{
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
.
SESSION_VALID_TIME
,
TimeUnit
.
SECONDS
);
Constants
.
Session
.
SESSION_VALID_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
.
SESSION_VALID_TIME
,
TimeUnit
.
SECONDS
);
stringRedisTemplate
.
opsForValue
().
set
(
key
,
token
,
expire
,
TimeUnit
.
SECONDS
);
setUserIdTokenKeys
(
sessionValue
.
getUser
().
getId
(),
key
);
setUserIdTokenKeys
(
sessionValue
.
getUser
().
getId
(),
key
);
}
}
...
...
src/main/java/cn/quantgroup/xyqb/session/XyqbSessionContextHolder.java
View file @
f812088c
...
@@ -69,6 +69,7 @@ public class XyqbSessionContextHolder {
...
@@ -69,6 +69,7 @@ public class XyqbSessionContextHolder {
SessionStruct
sessionStruct
=
new
SessionStruct
();
SessionStruct
sessionStruct
=
new
SessionStruct
();
sessionStruct
.
setSid
(
token
);
sessionStruct
.
setSid
(
token
);
sessionStruct
.
setValues
(
values
);
sessionStruct
.
setValues
(
values
);
sessionStruct
.
setExpire
(
redisTemplate
.
getExpire
(
Constants
.
Session
.
USER_SESSION_CACHE
+
token
));
return
sessionStruct
;
return
sessionStruct
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
warn
(
"[XyqbSessionContextHolder][getXSessionFromRedis] 序列化SessionValue出错:sid:{},sessionValue:{}"
,
token
,
result
,
e
);
log
.
warn
(
"[XyqbSessionContextHolder][getXSessionFromRedis] 序列化SessionValue出错:sid:{},sessionValue:{}"
,
token
,
result
,
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