Skip to content

Commit

Permalink
fix bugs in DefaultMirrorAccessController
Browse files Browse the repository at this point in the history
  • Loading branch information
ikhoon committed Jan 21, 2025
1 parent e81bdc3 commit 5cae78a
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ public CompletableFuture<Boolean> isAllowed(String repoUri) {
.collect(toImmutableList());
for (HasRevision<MirrorAccessControl> entity : sorted) {
try {
if (repoUri.equals(entity.object().targetPattern()) ||
repoUri.matches(entity.object().targetPattern())) {
if (matchesRepoUri(repoUri, entity)) {
return entity.object().allow();
}
} catch (Exception e) {
Expand All @@ -142,9 +141,9 @@ public CompletableFuture<Map<String, Boolean>> isAllowed(Iterable<String> repoUr
acl.stream()
.sorted(AccessControlComparator.INSTANCE)
.collect(toImmutableList());
return Streams.stream(repoUris).collect(toImmutableMap(uri -> uri, uri -> {
return Streams.stream(repoUris).distinct().collect(toImmutableMap(uri -> uri, uri -> {
for (HasRevision<MirrorAccessControl> entity : sorted) {
if (uri.matches(entity.object().targetPattern())) {
if (matchesRepoUri(uri, entity)) {
return entity.object().allow();
}
}
Expand All @@ -154,6 +153,16 @@ public CompletableFuture<Map<String, Boolean>> isAllowed(Iterable<String> repoUr
});
}

private static boolean matchesRepoUri(String repoUri, HasRevision<MirrorAccessControl> entity) {
final String targetPattern = entity.object().targetPattern();
try {
return repoUri.equals(targetPattern) || repoUri.matches(targetPattern);
} catch (Exception e) {
logger.warn("Failed to match the target pattern: {}", targetPattern, e);
return false;
}
}

public CompletableFuture<Void> delete(String id, Author author) {
return repository().delete(id, author, "Delete '" + id + '\'')
.thenAccept(unused -> {
Expand Down

0 comments on commit 5cae78a

Please sign in to comment.