Skip to content

Commit

Permalink
fix: auth issue for target. (#634)
Browse files Browse the repository at this point in the history
* fix: auth issue for target.

* docs: update CHANGELOG.MD
  • Loading branch information
ChiveHao committed Jul 26, 2024
1 parent 9bc9592 commit 4e819c8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
## 问题修复

- 条目更新乐观锁问题 #631
- 授权的附件接口判断问题 #633

# 0.14.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,9 @@ public Mono<AuthorizationDecision> check(Mono<Authentication> authentication,

if (AuthorityType.API.equals(type)) {

if (target.contains("/**")) {
String apiPrefix = target.substring(0, target.lastIndexOf("/**"));
if (!granted && path.contains(apiPrefix)) {
granted = true;
continue;
}


} else {
if (!granted && path.equalsIgnoreCase(target)) {
granted = true;
continue;
}
if (authTarget(target, path, granted)) {
granted = true;
continue;
}

if (Authorization.Target.ALL.equals(target)
Expand All @@ -108,8 +98,10 @@ public Mono<AuthorizationDecision> check(Mono<Authentication> authentication,

if (!Authorization.Authority.ALL.equals(author) && author.startsWith("HTTP")) {
if (author.contains(method.name())) {
granted = true;
continue;
if (authTarget(target, path, granted)) {
granted = true;
continue;
}
}
}
}
Expand All @@ -125,4 +117,20 @@ public Mono<AuthorizationDecision> check(Mono<Authentication> authentication,
});
}

private boolean authTarget(String target, String path, boolean granted) {
if (target.contains("/**")) {
String apiPrefix = target.substring(0, target.lastIndexOf("/**"));
if (!granted && path.contains(apiPrefix)) {
return true;
}


} else {
if (!granted && path.equalsIgnoreCase(target)) {
return true;
}
}
return granted;
}

}

0 comments on commit 4e819c8

Please sign in to comment.