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
9bbd077e
Commit
9bbd077e
authored
Sep 24, 2025
by
xuepeng.chang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stms 权限系统校验token 修改
parent
ff894e42
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
79 additions
and
14 deletions
+79
-14
Constants.java
src/main/java/cn/quantgroup/xyqb/Constants.java
+5
-0
StmsInnerInterceptor.java
.../java/cn/quantgroup/xyqb/filter/StmsInnerInterceptor.java
+10
-14
ISessionService.java
...a/cn/quantgroup/xyqb/service/session/ISessionService.java
+2
-0
SessionServiceImpl.java
...ntgroup/xyqb/service/session/impl/SessionServiceImpl.java
+27
-0
XyqbSessionContextHolder.java
.../cn/quantgroup/xyqb/session/XyqbSessionContextHolder.java
+35
-0
No files found.
src/main/java/cn/quantgroup/xyqb/Constants.java
View file @
9bbd077e
...
@@ -232,6 +232,11 @@ public interface Constants {
...
@@ -232,6 +232,11 @@ public interface Constants {
Long
SESSION_VALID_TIME
=
15
*
24
*
60
*
60L
;
Long
SESSION_VALID_TIME
=
15
*
24
*
60
*
60L
;
Long
SESSION_EXCHANGE_VALID_TIME
=
380L
;
Long
SESSION_EXCHANGE_VALID_TIME
=
380L
;
}
}
interface
StmsSession
{
String
STMS_USER_SESSION_CACHE
=
"user:stms:session:"
;
// stms会话有效期24小时
Long
STMS_SESSION_VALID_TIME
=
24
*
24
*
60
*
60L
;
}
interface
UserAvatar
{
interface
UserAvatar
{
String
AVATAR_DEFAULT
=
"https://avatar.xyqb.com/default_avatar.png"
;
String
AVATAR_DEFAULT
=
"https://avatar.xyqb.com/default_avatar.png"
;
...
...
src/main/java/cn/quantgroup/xyqb/filter/StmsInnerInterceptor.java
View file @
9bbd077e
...
@@ -8,10 +8,10 @@ import cn.quantgroup.xyqb.model.session.SessionStruct;
...
@@ -8,10 +8,10 @@ import cn.quantgroup.xyqb.model.session.SessionStruct;
import
cn.quantgroup.xyqb.remote.StmsRemoteService
;
import
cn.quantgroup.xyqb.remote.StmsRemoteService
;
import
cn.quantgroup.xyqb.service.session.ISessionService
;
import
cn.quantgroup.xyqb.service.session.ISessionService
;
import
cn.quantgroup.xyqb.session.XyqbSessionContextHolder
;
import
cn.quantgroup.xyqb.session.XyqbSessionContextHolder
;
import
cn.quantgroup.xyqb.util.StringUtils
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.collect.Maps
;
import
com.google.common.collect.Maps
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.web.servlet.HandlerInterceptor
;
import
org.springframework.web.servlet.HandlerInterceptor
;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.ModelAndView
;
...
@@ -38,12 +38,11 @@ public class StmsInnerInterceptor implements HandlerInterceptor {
...
@@ -38,12 +38,11 @@ public class StmsInnerInterceptor implements HandlerInterceptor {
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
throws
Exception
{
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
throws
Exception
{
//所有开放出去的外部接口,都需要验证租户id和注册来源
//所有开放出去的外部接口,都需要验证租户id和注册来源
String
tenantId
=
request
.
getHeader
(
Constants
.
X_AUTH_TENANT
);
String
tenantId
=
request
.
getHeader
(
Constants
.
X_AUTH_TENANT
);
String
registeredFrom
=
request
.
getHeader
(
Constants
.
X_AUTH_FROM
);
String
registeredFrom
=
request
.
getHeader
(
Constants
.
X_AUTH_FROM
);
try
{
try
{
registeredFrom
=
org
.
apache
.
commons
.
lang3
.
StringUtils
.
isEmpty
(
registeredFrom
)
?
request
.
getHeader
(
Constants
.
X_AUTH_FROM_
)
:
registeredFrom
;
registeredFrom
=
StringUtils
.
isEmpty
(
registeredFrom
)
?
request
.
getHeader
(
Constants
.
X_AUTH_FROM_
)
:
registeredFrom
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
warn
(
"registeredFrom获取异常"
,
e
);
registeredFrom
=
"0"
;
registeredFrom
=
"0"
;
}
}
String
stmsToken
=
request
.
getHeader
(
Constants
.
X_AUTH_TOKEN
);
String
stmsToken
=
request
.
getHeader
(
Constants
.
X_AUTH_TOKEN
);
...
@@ -55,8 +54,8 @@ public class StmsInnerInterceptor implements HandlerInterceptor {
...
@@ -55,8 +54,8 @@ public class StmsInnerInterceptor implements HandlerInterceptor {
throw
new
BizException
(
BizExceptionEnum
.
UN_EXIT_STMS_TOKEN
);
throw
new
BizException
(
BizExceptionEnum
.
UN_EXIT_STMS_TOKEN
);
}
}
SessionStruct
sessionStruct
=
XyqbSessionContextHolder
.
get
XSessionFromRedis
(
stmsToken
,
Integer
.
valueOf
(
tenantId
),
org
.
apache
.
commons
.
lang3
.
StringUtils
.
isEmpty
(
registeredFrom
)
?
null
:
Long
.
valueOf
(
registeredFrom
));
SessionStruct
sessionStruct
=
XyqbSessionContextHolder
.
get
StmsXSessionFromRedis
(
stmsToken
,
Integer
.
valueOf
(
tenantId
),
StringUtils
.
isEmpty
(
registeredFrom
)
?
null
:
Long
.
valueOf
(
registeredFrom
));
log
.
info
(
"从redis获取sessionStruct结果:{}"
,
JSONObject
.
toJSONString
(
sessionStruct
));
log
.
info
(
"
stms权限
从redis获取sessionStruct结果:{}"
,
JSONObject
.
toJSONString
(
sessionStruct
));
if
(
sessionStruct
==
null
)
{
if
(
sessionStruct
==
null
)
{
OauthResult
oauthResult
=
stmsRemoteService
.
checkToken
(
stmsToken
);
OauthResult
oauthResult
=
stmsRemoteService
.
checkToken
(
stmsToken
);
if
(
oauthResult
!=
null
&&
2000
==
oauthResult
.
getCode
())
{
if
(
oauthResult
!=
null
&&
2000
==
oauthResult
.
getCode
())
{
...
@@ -64,23 +63,20 @@ public class StmsInnerInterceptor implements HandlerInterceptor {
...
@@ -64,23 +63,20 @@ public class StmsInnerInterceptor implements HandlerInterceptor {
String
userId
=
String
.
valueOf
(
linkedHashMap
.
get
(
"id"
));
String
userId
=
String
.
valueOf
(
linkedHashMap
.
get
(
"id"
));
String
userName
=
String
.
valueOf
(
linkedHashMap
.
get
(
"name"
));
String
userName
=
String
.
valueOf
(
linkedHashMap
.
get
(
"name"
));
sessionStruct
=
XyqbSessionContextHolder
.
initSTMSSession
(
stmsToken
,
userId
,
userName
);
sessionStruct
=
XyqbSessionContextHolder
.
initSTMSSession
(
stmsToken
,
userId
,
userName
);
sessionService
.
persistS
ession
(
sessionStruct
.
getSid
(),
sessionStruct
.
getValues
(),
sessionStruct
.
getTenantId
());
sessionService
.
persistS
tmsSession
(
sessionStruct
.
getSid
(),
sessionStruct
.
getValues
(),
Constants
.
StmsSession
.
STMS_SESSION_VALID_TIME
,
sessionStruct
.
getTenantId
());
}
else
{
}
else
{
throw
new
BizException
(
BizExceptionEnum
.
UN_PERMISSION_STMS
);
throw
new
BizException
(
BizExceptionEnum
.
UN_PERMISSION_STMS
);
}
}
}
else
{
}
else
{
//session续期
//s
tms s
ession续期
sessionService
.
persistS
ession
(
sessionStruct
.
getSid
(),
sessionStruct
.
getValues
(),
sessionStruct
.
getTenantId
());
sessionService
.
persistS
tmsSession
(
sessionStruct
.
getSid
(),
sessionStruct
.
getValues
(),
Constants
.
StmsSession
.
STMS_SESSION_VALID_TIME
,
sessionStruct
.
getTenantId
());
log
.
info
(
"sessionStruct续期完成:{}"
,
JSONObject
.
toJSONString
(
sessionStruct
));
log
.
info
(
"s
tms权限 s
essionStruct续期完成:{}"
,
JSONObject
.
toJSONString
(
sessionStruct
));
}
}
//校验接口权限
//校验接口权限
//smts 租户概念不明确,暂且先统一为560761
//smts 租户概念不明确,暂且先统一为560761
String
tenantIdTmp
=
"560761"
;
String
tenantIdTmp
=
"560761"
;
OauthResult
permissionResult
=
stmsRemoteService
.
checkPermission
(
stmsToken
,
OauthResult
permissionResult
=
stmsRemoteService
.
checkPermission
(
stmsToken
,
request
.
getRequestURI
(),
tenantIdTmp
);
request
.
getRequestURI
(),
tenantIdTmp
);
if
(
permissionResult
!=
null
&&
2000
==
permissionResult
.
getCode
())
{
if
(
permissionResult
!=
null
&&
2000
==
permissionResult
.
getCode
())
{
return
true
;
return
true
;
}
else
{
}
else
{
...
...
src/main/java/cn/quantgroup/xyqb/service/session/ISessionService.java
View file @
9bbd077e
...
@@ -19,6 +19,8 @@ public interface ISessionService {
...
@@ -19,6 +19,8 @@ public interface ISessionService {
void
persistSession
(
String
token
,
SessionValue
sessionValue
,
Integer
tenantId
);
void
persistSession
(
String
token
,
SessionValue
sessionValue
,
Integer
tenantId
);
void
persistSession
(
String
token
,
SessionValue
sessionValue
,
Long
time
,
Integer
tenantId
);
void
persistSession
(
String
token
,
SessionValue
sessionValue
,
Long
time
,
Integer
tenantId
);
void
persistStmsSession
(
String
stmsToken
,
SessionValue
sessionValue
,
Long
time
,
Integer
tenantId
);
void
deleteByUserId
(
long
userId
,
Integer
tenantId
);
void
deleteByUserId
(
long
userId
,
Integer
tenantId
);
void
deleteUserCatch
(
User
user
,
Integer
tenantId
);
void
deleteUserCatch
(
User
user
,
Integer
tenantId
);
...
...
src/main/java/cn/quantgroup/xyqb/service/session/impl/SessionServiceImpl.java
View file @
9bbd077e
...
@@ -260,6 +260,33 @@ public class SessionServiceImpl implements ISessionService {
...
@@ -260,6 +260,33 @@ public class SessionServiceImpl implements ISessionService {
}
}
}
}
@Override
public
void
persistStmsSession
(
String
stmsToken
,
SessionValue
sessionValue
,
Long
time
,
Integer
tenantId
)
{
Timestamp
current
=
new
Timestamp
(
System
.
currentTimeMillis
());
if
(
sessionValue
==
null
)
{
sessionValue
=
new
SessionValue
();
}
if
(
sessionValue
.
getLoginProperties
()
==
null
)
{
sessionValue
.
setLoginProperties
(
new
LoginProperties
());
}
LoginProperties
loginProperties
=
sessionValue
.
getLoginProperties
();
loginProperties
.
setTenantId
(
tenantId
);
sessionValue
.
setLoginProperties
(
loginProperties
);
sessionValue
.
setLastAccessTime
(
current
);
String
json
=
JSON
.
toJSONString
(
sessionValue
);
String
key
;
if
(
Objects
.
isNull
(
tenantId
)
||
UserConstant
.
defaultTenantId
.
equals
(
tenantId
))
{
key
=
Constants
.
StmsSession
.
STMS_USER_SESSION_CACHE
+
stmsToken
;
}
else
{
key
=
Constants
.
StmsSession
.
STMS_USER_SESSION_CACHE
+
tenantId
+
":"
+
stmsToken
;
}
stringRedisTemplate
.
opsForValue
().
set
(
key
,
json
,
time
,
TimeUnit
.
SECONDS
);
}
/**
/**
* 设置用户token集合方便注销使用
* 设置用户token集合方便注销使用
*
*
...
...
src/main/java/cn/quantgroup/xyqb/session/XyqbSessionContextHolder.java
View file @
9bbd077e
...
@@ -185,6 +185,41 @@ public class XyqbSessionContextHolder {
...
@@ -185,6 +185,41 @@ public class XyqbSessionContextHolder {
}
}
}
}
public
static
SessionStruct
getStmsXSessionFromRedis
(
String
token
,
Integer
tenantId
,
Long
registeredFrom
)
{
String
stmsTokenKey
;
if
(
UserConstant
.
defaultTenantId
.
equals
(
tenantId
))
{
stmsTokenKey
=
Constants
.
StmsSession
.
STMS_USER_SESSION_CACHE
+
token
;
}
else
{
stmsTokenKey
=
Constants
.
StmsSession
.
STMS_USER_SESSION_CACHE
+
tenantId
+
":"
+
token
;
}
String
result
=
redisTemplate
.
opsForValue
().
get
(
stmsTokenKey
);
if
(
StringUtils
.
isEmpty
(
result
))
{
log
.
warn
(
"[XyqbSessionContextHolder][getStmsXSessionFromRedis] session data 未找到:Tokekn:{},stmsTokenKey:{},sessionValue:{}"
,
token
,
stmsTokenKey
,
result
);
return
null
;
}
try
{
SessionValue
values
=
JSON
.
parseObject
(
result
,
SessionValue
.
class
);
SessionStruct
sessionStruct
=
new
SessionStruct
();
if
(
values
==
null
)
{
log
.
warn
(
"[XyqbSessionContextHolder][getStmsXSessionFromRedis] session data 序列化失败:token:{},stmsTokenKey:{},sessionValue:{}"
,
token
,
stmsTokenKey
,
result
);
return
null
;
}
else
{
if
(
values
.
getLoginProperties
()
!=
null
)
{
sessionStruct
.
setTenantId
(
values
.
getLoginProperties
().
getTenantId
());
sessionStruct
.
setRegisteredFrom
(
registeredFrom
);
}
}
sessionStruct
.
setSid
(
token
);
sessionStruct
.
setValues
(
values
);
sessionStruct
.
setExpire
(
redisTemplate
.
getExpire
(
stmsTokenKey
));
return
sessionStruct
;
}
catch
(
Exception
e
)
{
log
.
warn
(
"[XyqbSessionContextHolder][getXSessionFromRedis] 序列化SessionValue出错:Tokekn:{},stmsTokenKey:{},sessionValue:{}"
,
token
,
stmsTokenKey
,
result
,
e
);
return
null
;
}
}
public
static
void
releaseSession
()
{
public
static
void
releaseSession
()
{
threadSession
.
remove
();
threadSession
.
remove
();
}
}
...
...
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