Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yanxuan-qc-change-system
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
yx-qc-change-flow
yanxuan-qc-change-system
Commits
8f2e61a9
Commit
8f2e61a9
authored
Dec 07, 2022
by
“zcwang”
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add: 登录态校验
parent
ccbd3cff
Pipeline
#43485
passed with stages
in 2 minutes 33 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
0 deletions
+91
-0
AdminUserHolder.java
...ease/mail/yanxuan/change/common/bean/AdminUserHolder.java
+39
-0
AdminUserLoginInterceptor.java
.../yanxuan/change/web/config/AdminUserLoginInterceptor.java
+52
-0
No files found.
yanxuan-qc-change-system-common/src/main/java/com/netease/mail/yanxuan/change/common/bean/AdminUserHolder.java
0 → 100644
View file @
8f2e61a9
/**
* @(#)UserHolder.java, 2020/12/9.
* <p/>
* Copyright 2020 Netease, Inc. All rights reserved.
* NETEASE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
package
com
.
netease
.
mail
.
yanxuan
.
change
.
common
.
bean
;
import
org.springframework.stereotype.Component
;
/**
* B端管理系统用户信息
*
* @author: 莫闲
* @date: 2020-12-09 13:19
**/
@Component
public
class
AdminUserHolder
{
// 当前登录用户名线程绑定
private
static
ThreadLocal
<
String
>
userThreadLocal
=
new
ThreadLocal
<>();
public
static
void
clear
()
{
userThreadLocal
.
remove
();
}
/**
* 获取用户名
*
* @return 用户名,null-未登录
*/
public
static
String
getUserName
()
{
return
userThreadLocal
.
get
();
}
public
static
void
setUserName
(
String
userName
)
{
userThreadLocal
.
set
(
userName
);
}
}
yanxuan-qc-change-system-web/src/main/java/com/netease/mail/yanxuan/change/web/config/AdminUserLoginInterceptor.java
0 → 100644
View file @
8f2e61a9
package
com
.
netease
.
mail
.
yanxuan
.
change
.
web
.
config
;
import
java.util.Enumeration
;
import
java.util.HashMap
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.servlet.HandlerInterceptor
;
import
org.springframework.web.servlet.ModelAndView
;
import
com.netease.mail.yanxuan.change.common.bean.AdminUserHolder
;
import
lombok.extern.slf4j.Slf4j
;
@Slf4j
@Component
public
class
AdminUserLoginInterceptor
implements
HandlerInterceptor
{
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
throws
Exception
{
Map
<
String
,
String
>
headerMap
=
new
HashMap
<>();
Enumeration
<
String
>
enumeration
=
request
.
getHeaderNames
();
while
(
enumeration
.
hasMoreElements
())
{
String
name
=
enumeration
.
nextElement
();
String
value
=
request
.
getHeader
(
name
);
headerMap
.
put
(
name
,
value
);
}
log
.
info
(
"adminUserLoginInterceptor headerMap ={}"
,
headerMap
);
String
uid
=
request
.
getHeader
(
"uid"
);
log
.
info
(
"adminUserLoginInterceptor uid ={}"
,
uid
);
AdminUserHolder
.
setUserName
(
uid
);
return
true
;
}
@Override
public
void
postHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
ModelAndView
modelAndView
)
throws
Exception
{
}
@Override
public
void
afterCompletion
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
Exception
ex
)
throws
Exception
{
AdminUserHolder
.
clear
();
}
}
\ No newline at end of file
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