Skip to content

Commit

Permalink
Fix sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
enricovianello committed Oct 4, 2024
1 parent eb50688 commit 9a98b3d
Showing 1 changed file with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class WlcgStructuredPathAuthorizationPdp
public static final String STORAGE_MODIFY = "storage.modify";
public static final String STORAGE_CREATE = "storage.create";

protected static final Set<String> READ_SCOPES = Sets.newHashSet(STORAGE_READ, STORAGE_STAGE);
protected static final Set<String> WRITE_SCOPES = Sets.newHashSet(STORAGE_CREATE, STORAGE_MODIFY);
protected static final Set<String> ALL_STORAGE_SCOPES =
Sets.newHashSet(STORAGE_READ, STORAGE_MODIFY, STORAGE_CREATE, STORAGE_STAGE);

Expand Down Expand Up @@ -128,35 +130,35 @@ boolean filterMatcherByRequest(HttpServletRequest request, String method,
StructuredPathScopeMatcher m, boolean requestedResourceExists) {

if (CATCHALL_METHODS.contains(method)) {
return ALL_STORAGE_SCOPES.stream().anyMatch(prefix -> m.getPrefix().equals(prefix));
return ALL_STORAGE_SCOPES.stream().anyMatch(prefix -> prefix.equals(m.getPrefix()));
}

if (READONLY_METHODS.contains(method)) {
return m.getPrefix().equals(STORAGE_READ) || m.getPrefix().equals(STORAGE_STAGE);
return READ_SCOPES.contains(m.getPrefix());
}
if (REPLACE_METHODS.contains(method)) {
if (requestedResourceExists) {
return m.getPrefix().equals(STORAGE_MODIFY);
return STORAGE_MODIFY.equals(m.getPrefix());
}
return m.getPrefix().equals(STORAGE_CREATE) || m.getPrefix().equals(STORAGE_MODIFY);
return WRITE_SCOPES.contains(m.getPrefix());
}
if (MODIFY_METHODS.contains(method)) {
return m.getPrefix().equals(STORAGE_MODIFY);
return STORAGE_MODIFY.equals(m.getPrefix());
}
if (COPY_METHOD.equals(method)) {

if (isPullTpc(request, localUrlService)) {
if (requestedResourceExists) {
return m.getPrefix().equals(STORAGE_MODIFY);
return STORAGE_MODIFY.equals(m.getPrefix());
}
return m.getPrefix().equals(STORAGE_CREATE) || m.getPrefix().equals(STORAGE_MODIFY);
return WRITE_SCOPES.contains(m.getPrefix());
}
return m.getPrefix().equals(STORAGE_READ) || m.getPrefix().equals(STORAGE_STAGE);
return READ_SCOPES.contains(m.getPrefix());

}

if (MOVE_METHOD.equals(method)) {
return m.getPrefix().equals(STORAGE_MODIFY);
return STORAGE_MODIFY.equals(m.getPrefix());
}

throw new IllegalArgumentException(format(ERROR_UNSUPPORTED_METHOD_PATTERN, method));
Expand Down Expand Up @@ -214,9 +216,9 @@ public PathAuthorizationResult authorizeRequest(PathAuthorizationRequest authzRe

if ("MKCOL".equals(method)) {
scopeMatchers = scopeMatchers.stream()
.filter(m -> filterMatcherByRequest(request, method, m, requestedResourceExists))
.filter(m -> m.matchesPathIncludingParents(saPath))
.collect(toList());
.filter(m -> filterMatcherByRequest(request, method, m, requestedResourceExists))
.filter(m -> m.matchesPathIncludingParents(saPath))
.collect(toList());
} else {
scopeMatchers = scopeMatchers.stream()
.filter(m -> filterMatcherByRequest(request, method, m, requestedResourceExists))
Expand Down

0 comments on commit 9a98b3d

Please sign in to comment.