Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Pig
提交
80e1b9f6
P
Pig
项目概览
int
/
Pig
上一次同步 大约 1 年
通知
8
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Pig
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
80e1b9f6
编写于
8月 11, 2021
作者:
W
wjie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
🐛
Fixing a bug. closed #I44U16 token失效后 没有json错误返回 而是报500
上级
9cf79134
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
58 addition
and
3 deletion
+58
-3
pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PigWebResponseExceptionTranslator.java
...security/component/PigWebResponseExceptionTranslator.java
+2
-1
pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/ResourceAuthExceptionEntryPoint.java
...n/security/component/ResourceAuthExceptionEntryPoint.java
+9
-2
pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/exception/TokenInvalidException.java
.../pig/common/security/exception/TokenInvalidException.java
+47
-0
未找到文件。
pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/PigWebResponseExceptionTranslator.java
浏览文件 @
80e1b9f6
...
...
@@ -65,10 +65,11 @@ public class PigWebResponseExceptionTranslator implements WebResponseExceptionTr
return
handleOAuth2Exception
(
new
InvalidException
(
ase
.
getMessage
(),
ase
));
}
// token 过期 特殊处理 返回 424 不是 401
ase
=
(
InvalidTokenException
)
throwableAnalyzer
.
getFirstThrowableOfType
(
InvalidTokenException
.
class
,
causeChain
);
if
(
ase
!=
null
)
{
return
handleOAuth2Exception
(
new
Unauthorize
dException
(
ase
.
getMessage
(),
ase
));
return
handleOAuth2Exception
(
new
TokenInvali
dException
(
ase
.
getMessage
(),
ase
));
}
ase
=
(
HttpRequestMethodNotSupportedException
)
throwableAnalyzer
...
...
pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/component/ResourceAuthExceptionEntryPoint.java
浏览文件 @
80e1b9f6
...
...
@@ -22,6 +22,7 @@ import com.pig4cloud.pig.common.core.constant.CommonConstants;
import
com.pig4cloud.pig.common.core.util.R
;
import
lombok.RequiredArgsConstructor
;
import
lombok.SneakyThrows
;
import
org.springframework.security.authentication.InsufficientAuthenticationException
;
import
org.springframework.security.core.AuthenticationException
;
import
org.springframework.security.web.AuthenticationEntryPoint
;
...
...
@@ -45,12 +46,18 @@ public class ResourceAuthExceptionEntryPoint implements AuthenticationEntryPoint
response
.
setCharacterEncoding
(
CommonConstants
.
UTF8
);
response
.
setContentType
(
CommonConstants
.
CONTENT_TYPE
);
R
<
String
>
result
=
new
R
<>();
result
.
setCode
(
HttpStatus
.
HTTP_UNAUTHORIZED
);
result
.
setCode
(
CommonConstants
.
FAIL
);
response
.
setStatus
(
HttpStatus
.
HTTP_UNAUTHORIZED
);
if
(
authException
!=
null
)
{
result
.
setMsg
(
"error"
);
result
.
setData
(
authException
.
getMessage
());
}
response
.
setStatus
(
HttpStatus
.
HTTP_UNAUTHORIZED
);
// 针对令牌过期返回特殊的 424
if
(
authException
instanceof
InsufficientAuthenticationException
)
{
response
.
setStatus
(
org
.
springframework
.
http
.
HttpStatus
.
FAILED_DEPENDENCY
.
value
());
result
.
setMsg
(
"token expire"
);
}
PrintWriter
printWriter
=
response
.
getWriter
();
printWriter
.
append
(
objectMapper
.
writeValueAsString
(
result
));
}
...
...
pig-common/pig-common-security/src/main/java/com/pig4cloud/pig/common/security/exception/TokenInvalidException.java
0 → 100644
浏览文件 @
80e1b9f6
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package
com.pig4cloud.pig.common.security.exception
;
import
com.fasterxml.jackson.databind.annotation.JsonSerialize
;
import
com.pig4cloud.pig.common.security.component.PigAuth2ExceptionSerializer
;
import
org.springframework.http.HttpStatus
;
/**
* @author lengleng
* @date 2021-08-05
* <p>
* 令牌不合法
*/
@JsonSerialize
(
using
=
PigAuth2ExceptionSerializer
.
class
)
public
class
TokenInvalidException
extends
PigAuth2Exception
{
public
TokenInvalidException
(
String
msg
,
Throwable
t
)
{
super
(
msg
);
}
@Override
public
String
getOAuth2ErrorCode
()
{
return
"invalid_token"
;
}
@Override
public
int
getHttpErrorCode
()
{
return
HttpStatus
.
FAILED_DEPENDENCY
.
value
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录