Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
D
dataease
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
zhu
dataease
Commits
3fd5e678
提交
3fd5e678
authored
6月 04, 2021
作者:
wangjiahao
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/main' into main
上级
0f2f3983
ef769da2
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
26 行增加
和
77 行删除
+26
-77
JWTFilter.java
backend/src/main/java/io/dataease/auth/filter/JWTFilter.java
+7
-17
en.js
frontend/src/lang/en.js
+5
-1
tw.js
frontend/src/lang/tw.js
+5
-1
zh.js
frontend/src/lang/zh.js
+5
-1
request.js
frontend/src/utils/request.js
+4
-57
没有找到文件。
backend/src/main/java/io/dataease/auth/filter/JWTFilter.java
浏览文件 @
3fd5e678
...
@@ -6,6 +6,7 @@ import io.dataease.auth.entity.TokenInfo;
...
@@ -6,6 +6,7 @@ import io.dataease.auth.entity.TokenInfo;
import
io.dataease.auth.service.AuthUserService
;
import
io.dataease.auth.service.AuthUserService
;
import
io.dataease.auth.util.JWTUtils
;
import
io.dataease.auth.util.JWTUtils
;
import
io.dataease.commons.utils.CommonBeanFactory
;
import
io.dataease.commons.utils.CommonBeanFactory
;
import
io.dataease.commons.utils.LogUtil
;
import
io.dataease.i18n.Translator
;
import
io.dataease.i18n.Translator
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.shiro.authc.AuthenticationException
;
import
org.apache.shiro.authc.AuthenticationException
;
...
@@ -72,10 +73,11 @@ public class JWTFilter extends BasicHttpAuthenticationFilter {
...
@@ -72,10 +73,11 @@ public class JWTFilter extends BasicHttpAuthenticationFilter {
boolean
loginSuccess
=
executeLogin
(
request
,
response
);
boolean
loginSuccess
=
executeLogin
(
request
,
response
);
return
loginSuccess
;
return
loginSuccess
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
LogUtil
.
error
(
e
);
if
(
e
instanceof
AuthenticationException
&&
StringUtils
.
equals
(
e
.
getMessage
(),
expireMessage
)){
if
(
e
instanceof
AuthenticationException
&&
StringUtils
.
equals
(
e
.
getMessage
(),
expireMessage
)){
responseExpire
(
request
,
response
);
responseExpire
(
request
,
response
,
e
);
}
else
{
}
else
{
response401
(
request
,
respons
e
);
tokenError
(
request
,
response
,
e
);
}
}
}
}
}
}
...
@@ -125,29 +127,17 @@ public class JWTFilter extends BasicHttpAuthenticationFilter {
...
@@ -125,29 +127,17 @@ public class JWTFilter extends BasicHttpAuthenticationFilter {
return
super
.
preHandle
(
request
,
response
);
return
super
.
preHandle
(
request
,
response
);
}
}
/**
* 将非法请求跳转到 /401
private
void
tokenError
(
ServletRequest
req
,
ServletResponse
resp
,
Exception
e1
)
{
*/
private
void
response401
(
ServletRequest
req
,
ServletResponse
resp
)
{
try
{
HttpServletResponse
httpServletResponse
=
(
HttpServletResponse
)
resp
;
HttpServletResponse
httpServletResponse
=
(
HttpServletResponse
)
resp
;
httpServletResponse
.
addHeader
(
"Access-Control-Expose-Headers"
,
"authentication-status"
);
httpServletResponse
.
addHeader
(
"Access-Control-Expose-Headers"
,
"authentication-status"
);
httpServletResponse
.
setHeader
(
"authentication-status"
,
"invalid"
);
httpServletResponse
.
setHeader
(
"authentication-status"
,
"invalid"
);
httpServletResponse
.
setStatus
(
401
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
.
getMessage
());
}
}
}
private
void
responseExpire
(
ServletRequest
req
,
ServletResponse
resp
)
{
private
void
responseExpire
(
ServletRequest
req
,
ServletResponse
resp
,
Exception
e1
)
{
try
{
HttpServletResponse
httpServletResponse
=
(
HttpServletResponse
)
resp
;
HttpServletResponse
httpServletResponse
=
(
HttpServletResponse
)
resp
;
httpServletResponse
.
addHeader
(
"Access-Control-Expose-Headers"
,
"authentication-status"
);
httpServletResponse
.
addHeader
(
"Access-Control-Expose-Headers"
,
"authentication-status"
);
httpServletResponse
.
setHeader
(
"authentication-status"
,
"login_expire"
);
httpServletResponse
.
setHeader
(
"authentication-status"
,
"login_expire"
);
httpServletResponse
.
setStatus
(
401
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
.
getMessage
());
}
}
}
}
}
frontend/src/lang/en.js
浏览文件 @
3fd5e678
...
@@ -285,7 +285,11 @@ export default {
...
@@ -285,7 +285,11 @@ export default {
char_can_not_more_50
:
'Can not more 50 char'
,
char_can_not_more_50
:
'Can not more 50 char'
,
share_success
:
'Share Success'
,
share_success
:
'Share Success'
,
input_id
:
'Please input ID'
,
input_id
:
'Please input ID'
,
input_pwd
:
'Please input password'
input_pwd
:
'Please input password'
,
message_box
:
{
alert
:
'Alert'
,
confirm
:
'Confirm'
}
},
},
documentation
:
{
documentation
:
{
documentation
:
'Documentation'
,
documentation
:
'Documentation'
,
...
...
frontend/src/lang/tw.js
浏览文件 @
3fd5e678
...
@@ -285,7 +285,11 @@ export default {
...
@@ -285,7 +285,11 @@ export default {
char_can_not_more_50
:
'不能超過50字符'
,
char_can_not_more_50
:
'不能超過50字符'
,
share_success
:
'分享成功'
,
share_success
:
'分享成功'
,
input_id
:
'請輸入ID'
,
input_id
:
'請輸入ID'
,
input_pwd
:
'請輸入密碼'
input_pwd
:
'請輸入密碼'
,
message_box
:
{
alert
:
'警告'
,
confirm
:
'確認'
}
},
},
documentation
:
{
documentation
:
{
documentation
:
'文檔'
,
documentation
:
'文檔'
,
...
...
frontend/src/lang/zh.js
浏览文件 @
3fd5e678
...
@@ -285,7 +285,11 @@ export default {
...
@@ -285,7 +285,11 @@ export default {
char_can_not_more_50
:
'不能超过50字符'
,
char_can_not_more_50
:
'不能超过50字符'
,
share_success
:
'分享成功'
,
share_success
:
'分享成功'
,
input_id
:
'请输入ID'
,
input_id
:
'请输入ID'
,
input_pwd
:
'请输入密码'
input_pwd
:
'请输入密码'
,
message_box
:
{
alert
:
'警告'
,
confirm
:
'确认'
}
},
},
documentation
:
{
documentation
:
{
documentation
:
'文档'
,
documentation
:
'文档'
,
...
...
frontend/src/utils/request.js
浏览文件 @
3fd5e678
...
@@ -57,7 +57,7 @@ const checkAuth = response => {
...
@@ -57,7 +57,7 @@ const checkAuth = response => {
if
(
response
.
headers
[
'authentication-status'
]
===
'login_expire'
)
{
if
(
response
.
headers
[
'authentication-status'
]
===
'login_expire'
)
{
const
message
=
i18n
.
t
(
'login.expires'
)
const
message
=
i18n
.
t
(
'login.expires'
)
store
.
dispatch
(
'user/setLoginMsg'
,
message
)
//
store.dispatch('user/setLoginMsg', message)
$alert
(
message
,
()
=>
{
$alert
(
message
,
()
=>
{
store
.
dispatch
(
'user/logout'
).
then
(()
=>
{
store
.
dispatch
(
'user/logout'
).
then
(()
=>
{
location
.
reload
()
location
.
reload
()
...
@@ -65,7 +65,7 @@ const checkAuth = response => {
...
@@ -65,7 +65,7 @@ const checkAuth = response => {
})
})
}
}
if
(
response
.
headers
[
'authentication-status'
]
===
'invalid'
||
response
.
status
===
401
)
{
if
(
response
.
headers
[
'authentication-status'
]
===
'invalid'
)
{
const
message
=
i18n
.
t
(
'login.tokenError'
)
const
message
=
i18n
.
t
(
'login.tokenError'
)
$alert
(
message
,
()
=>
{
$alert
(
message
,
()
=>
{
store
.
dispatch
(
'user/logout'
).
then
(()
=>
{
store
.
dispatch
(
'user/logout'
).
then
(()
=>
{
...
@@ -85,59 +85,6 @@ const checkAuth = response => {
...
@@ -85,59 +85,6 @@ const checkAuth = response => {
}
}
}
}
const
checkPermission
=
response
=>
{
// 请根据实际需求修改
if
(
response
.
status
===
404
)
{
location
.
href
=
'/404'
}
if
(
response
.
status
===
401
)
{
location
.
href
=
'/401'
}
}
// response interceptor
/**
service.interceptors.response.use(
response => {
const res = response.data
// if the custom code is not 20000, it is judged as an error.
if (res.code !== 20000) {
Message({
message: res.message || 'Error',
type: 'error',
duration: 5 * 1000
})
// 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
// to re-login
MessageBox.confirm('You have been logged out, you can cancel to stay on this page, or log in again', 'Confirm logout', {
confirmButtonText: 'Re-Login',
cancelButtonText: 'Cancel',
type: 'warning'
}).then(() => {
store.dispatch('user/resetToken').then(() => {
location.reload()
})
})
}
return Promise.reject(new Error(res.message || 'Error'))
} else {
return res
}
},
error => {
console.log('err' + error) // for debug
Message({
message: error.message,
type: 'error',
duration: 5 * 1000
})
return Promise.reject(error)
}
)
*/
// 请根据实际需求修改
// 请根据实际需求修改
service
.
interceptors
.
response
.
use
(
response
=>
{
service
.
interceptors
.
response
.
use
(
response
=>
{
response
.
config
.
loading
&&
tryHideLoading
(
store
.
getters
.
currentPath
)
response
.
config
.
loading
&&
tryHideLoading
(
store
.
getters
.
currentPath
)
...
@@ -148,12 +95,12 @@ service.interceptors.response.use(response => {
...
@@ -148,12 +95,12 @@ service.interceptors.response.use(response => {
let
msg
let
msg
if
(
error
.
response
)
{
if
(
error
.
response
)
{
checkAuth
(
error
.
response
)
checkAuth
(
error
.
response
)
checkPermission
(
error
.
response
)
//
checkPermission(error.response)
msg
=
error
.
response
.
data
.
message
||
error
.
response
.
data
msg
=
error
.
response
.
data
.
message
||
error
.
response
.
data
}
else
{
}
else
{
msg
=
error
.
message
msg
=
error
.
message
}
}
!
error
.
config
.
hideMsg
&&
$error
(
msg
)
!
error
.
config
.
hideMsg
&&
(
!
error
.
config
.
headers
[
'authentication-status'
])
&&
$error
(
msg
)
return
Promise
.
reject
(
error
)
return
Promise
.
reject
(
error
)
})
})
export
default
service
export
default
service
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论