From 9a98b3d10fd699c353491b92e2b4f397e1f2aa39 Mon Sep 17 00:00:00 2001 From: Enrico Vianello Date: Fri, 4 Oct 2024 12:43:58 +0200 Subject: [PATCH] Fix sonar issues --- .../WlcgStructuredPathAuthorizationPdp.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/italiangrid/storm/webdav/authz/pdp/WlcgStructuredPathAuthorizationPdp.java b/src/main/java/org/italiangrid/storm/webdav/authz/pdp/WlcgStructuredPathAuthorizationPdp.java index 6a26c2ae..76db289c 100644 --- a/src/main/java/org/italiangrid/storm/webdav/authz/pdp/WlcgStructuredPathAuthorizationPdp.java +++ b/src/main/java/org/italiangrid/storm/webdav/authz/pdp/WlcgStructuredPathAuthorizationPdp.java @@ -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 READ_SCOPES = Sets.newHashSet(STORAGE_READ, STORAGE_STAGE); + protected static final Set WRITE_SCOPES = Sets.newHashSet(STORAGE_CREATE, STORAGE_MODIFY); protected static final Set ALL_STORAGE_SCOPES = Sets.newHashSet(STORAGE_READ, STORAGE_MODIFY, STORAGE_CREATE, STORAGE_STAGE); @@ -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)); @@ -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))