Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: Enhance 401 Error Handling by Refreshing Token in acquireClusterMetaData Method #6923

Open
wants to merge 6 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#6899](https://github.com/apache/incubator-seata/pull/6899)] fix file.conf read failed after package
- [[#6890](https://github.com/apache/incubator-seata/pull/6890)] fix designerJson to standardJson: subStateMachine compensateState cannot be recognized
- [[#6907](https://github.com/apache/incubator-seata/pull/6907)] fix the issue of Codecov not generating reports
- [[#6923](https://github.com/apache/incubator-seata/pull/6923)] Enhance 401 Error Handling by Refreshing Token

### optimize:
- [[#6826](https://github.com/apache/incubator-seata/pull/6826)] remove the branch registration operation of the XA read-only transaction
Expand Down Expand Up @@ -52,6 +53,7 @@ Thanks to these contributors for their code commits. Please report an unintended
- [dsomehan](https://github.com/dsomehan)
- [psxjoy](https://github.com/psxjoy)
- [xingfudeshi](https://github.com/xingfudeshi)
- [o-jimin](https://github.com/o-jimin)



Expand Down
2 changes: 2 additions & 0 deletions changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- [[#6899](https://github.com/apache/incubator-seata/pull/6899)] 修复file.conf打包后的读取
- [[#6890](https://github.com/apache/incubator-seata/pull/6890)] 修复saga设计json转标准json过程中: 子状态机补偿节点无法被识别
- [[#6907](https://github.com/apache/incubator-seata/pull/6907)] 修复Codecov未生成报告的问题
- [[#6923](https://github.com/apache/incubator-seata/pull/6923)] 增强 401 错误处理,通过刷新令牌

### optimize:
- [[#6826](https://github.com/apache/incubator-seata/pull/6826)] 移除只读XA事务的分支注册操作
Expand Down Expand Up @@ -54,6 +55,7 @@
- [dsomehan](https://github.com/dsomehan)
- [psxjoy](https://github.com/psxjoy)
- [xingfudeshi](https://github.com/xingfudeshi)
- [o-jimin](https://github.com/o-jimin)

同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。

Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,14 @@ private static void acquireClusterMetaData(String clusterName, String group) thr
try (CloseableHttpResponse httpResponse =
HttpClientUtil.doGet("http://" + tcAddress + "/metadata/v1/cluster", param, header, 1000)) {
if (httpResponse != null) {
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
response = EntityUtils.toString(httpResponse.getEntity(), StandardCharsets.UTF_8);
} else if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
if (StringUtils.isNotBlank(USERNAME) && StringUtils.isNotBlank(PASSWORD)) {
throw new RetryableException("Authentication failed!");
} else {
throw new AuthenticationFailedException("Authentication failed! you should configure the correct username and password.");
}
} else if (statusCode == HttpStatus.SC_UNAUTHORIZED) {
refreshToken(tcAddress);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove
(StringUtils.isNotBlank(USERNAME) && StringUtils.isNotBlank(PASSWORD)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it wasn't necessary, but having validation might be good, so I made the changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it wasn't necessary, but having validation might be good, so I made the changes.

I think refreshToken(tcAddress); should be placed after the condition check; otherwise, it will waste a call when the account password is empty

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially placed it outside the condition because refreshToken checks the account, but your point makes sense, so I moved it. Thanks for the feedback!

throw new RetryableException("Token refreshed, retrying request.");
} else {
throw new AuthenticationFailedException("Authentication failed! you should configure the correct username and password.");
}
}
MetadataResponse metadataResponse;
Expand Down
Loading