Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
isc-core
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
isc-v3.1-tmp
isc-core
Commits
4fb72f48
Commit
4fb72f48
authored
Sep 30, 2024
by
niewei
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/develop' into develop
parents
0335a9d6
1b14c3e3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
97 additions
and
0 deletions
+97
-0
ISCRequestPreFilter.java
...com/brilliance/isc/common/filter/ISCRequestPreFilter.java
+97
-0
No files found.
isc-common-service/src/main/java/com/brilliance/isc/common/filter/ISCRequestPreFilter.java
0 → 100644
View file @
4fb72f48
package
com
.
brilliance
.
isc
.
common
.
filter
;
import
com.alibaba.fastjson.JSON
;
import
com.brilliance.isc.common.api.bch.service.impl.BchServiceImpl
;
import
com.brilliance.isc.common.context.SettleContext
;
import
com.brilliance.isc.common.lock.BizLocker
;
import
com.brilliance.isc.common.login.res.LoginCacheVo
;
import
com.brilliance.isc.common.login.vo.LoginInfoVO
;
import
com.brilliance.isc.exception.RestBizException
;
import
com.brilliance.isc.vo.manager.SessionUserVo
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.ws.rs.container.ContainerRequestContext
;
import
javax.ws.rs.container.ContainerRequestFilter
;
import
javax.ws.rs.core.Context
;
import
javax.ws.rs.core.HttpHeaders
;
import
java.io.IOException
;
import
java.util.concurrent.TimeUnit
;
public
class
ISCRequestPreFilter
implements
ContainerRequestFilter
{
Logger
logger
=
LoggerFactory
.
getLogger
(
ISCRequestPreFilter
.
class
);
@Context
protected
HttpServletRequest
request
;
@Context
protected
HttpHeaders
header
;
@Resource
protected
SettleContext
settleContext
;
@Resource
protected
RedisTemplate
redisTemplate
;
@Resource
protected
BizLocker
bizLocker
;
@Override
public
void
filter
(
ContainerRequestContext
requestContext
)
throws
IOException
{
clearCache
();
String
requestURI
=
request
.
getRequestURI
();
logger
.
info
(
"本次请求的url["
+
requestURI
+
"]"
);
if
(
requestURI
.
contains
(
"login/verify"
)
||
requestURI
.
contains
(
"login/changeRole"
)
||
requestURI
.
contains
(
"login/changeOrg"
)){
return
;
}
//
String
token
=
requestContext
.
getHeaderString
(
"token"
);
Long
currentExpireTime
=
redisTemplate
.
getExpire
(
token
);
//判断token是否失效,失效则抛异常
if
(
token
==
null
||
token
.
isEmpty
()
||
currentExpireTime
<=
0
){
throw
RestBizException
.
TOKEN_EXPIRED
;
}
String
loginCache
=
(
String
)
redisTemplate
.
opsForValue
().
get
(
token
);
LoginCacheVo
loginCacheVo
=
JSON
.
parseObject
(
loginCache
,
LoginCacheVo
.
class
);
LoginInfoVO
loginInfoVO
=
loginCacheVo
.
getLoginInfo
();
//session
SessionUserVo
sessionUserVo
=
new
SessionUserVo
();
sessionUserVo
.
setId
(
loginInfoVO
.
getUserId
());
sessionUserVo
.
setName
(
loginInfoVO
.
getUsr
().
getName
());
sessionUserVo
.
setLogName
(
loginInfoVO
.
getUsername
());
sessionUserVo
.
setWorkOrg
(
loginInfoVO
.
getAccbchList
().
getBranch
());
sessionUserVo
.
setOwnOrgDepartmentNumber
(
loginInfoVO
.
getCurrentOrg
().
getDepartmentnumber
());
settleContext
.
setSessionUserVo
(
sessionUserVo
);
settleContext
.
simpleLoadSettleSession
();
this
.
clearUserLock
(
requestURI
,
sessionUserVo
);
//没失效则刷新redis的过期时间(120分钟)
redisTemplate
.
expire
(
token
,
120
,
TimeUnit
.
MINUTES
);
logger
.
info
(
"将用户的部分信息存入sessionUserVo中"
);
}
private
void
clearUserLock
(
String
requestURI
,
SessionUserVo
sessionUserVo
){
if
(
requestURI
.
indexOf
(
"/logout"
)
>
-
1
){
logger
.
info
(
"退出释放等钱用户锁"
);
bizLocker
.
unlockAllOfUser
(
sessionUserVo
.
getLogName
());
logger
.
info
(
"Filter中锁释放完毕"
);
}
}
/**
* 避免因为异常导致ThreadLocal未被清理
*/
private
void
clearCache
(){
SettleContext
.
removeUserSession
();
SettleContext
.
removeSessionUserVo
();
BchServiceImpl
.
removeBranchCacheMap
();
BchServiceImpl
.
removeBchInrCacheMap
();
}
}
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