Skip to content

Commit

Permalink
Reduce usage of Guava library
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Bassi committed Dec 25, 2024
1 parent e54fb07 commit 9ae143c
Show file tree
Hide file tree
Showing 42 changed files with 154 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import org.italiangrid.storm.webdav.config.StorageAreaConfiguration;
Expand All @@ -29,10 +31,8 @@
import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Service;

import com.google.common.base.Preconditions;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;

@Service
public class VOMSPolicyService implements AuthorizationPolicyService {
Expand Down Expand Up @@ -72,7 +72,7 @@ public VOMSPolicyService(StorageAreaConfiguration saConfig) {
public Set<GrantedAuthority> getSAPermissions(
Collection<? extends GrantedAuthority> authorities) {

Set<GrantedAuthority> saPermissions = Sets.newHashSet();
Set<GrantedAuthority> saPermissions = new HashSet<>();

authorities.stream()
.filter(VOMSVOAuthority.class::isInstance)
Expand All @@ -90,7 +90,7 @@ public Set<GrantedAuthority> getSAPermissions(

@Override
public Set<GrantedAuthority> getSAPermissions(Authentication authn) {
Preconditions.checkNotNull(authn);
Objects.requireNonNull(authn);
return getSAPermissions(authn.getAuthorities());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.security.cert.X509Certificate;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Optional;
Expand All @@ -31,8 +32,6 @@
import org.springframework.security.authentication.AuthenticationDetailsSource;
import org.springframework.security.core.GrantedAuthority;

import com.google.common.collect.Sets;

import eu.emi.security.authn.x509.proxy.ProxyUtils;

public class VOMSPreAuthDetailsSource
Expand All @@ -52,7 +51,7 @@ public VOMSPreAuthDetailsSource(VOMSACValidator vomsValidator,
@Override
public VOMSAuthenticationDetails buildDetails(HttpServletRequest request) {

Set<GrantedAuthority> authorities = Sets.newHashSet();
Set<GrantedAuthority> authorities = new HashSet<>();

List<VOMSAttribute> attributes = getAttributes(request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.italiangrid.storm.webdav.authz.pdp;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

Expand All @@ -26,8 +27,6 @@
import org.springframework.security.core.Authentication;
import org.springframework.security.web.util.matcher.RequestMatcher;

import com.google.common.collect.Lists;

public class PathAuthorizationPolicy {

public static final Logger LOG = LoggerFactory.getLogger(PathAuthorizationPolicy.class);
Expand Down Expand Up @@ -106,8 +105,8 @@ public static class Builder {

private PolicyEffect effect = PolicyEffect.DENY;

private List<RequestMatcher> requestMatchers = Lists.newArrayList();
private List<PrincipalMatcher> principalMatchers = Lists.newArrayList();
private List<RequestMatcher> requestMatchers = new ArrayList<>();
private List<PrincipalMatcher> principalMatchers = new ArrayList<>();

public Builder withSa(String sa) {
this.sa = sa;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;

import com.google.common.collect.Sets;

public class WlcgStructuredPathAuthorizationPdp
implements PathAuthorizationPdp, MatcherUtils, TpcUtils {

Expand All @@ -58,10 +56,10 @@ 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> READ_SCOPES = Set.of(STORAGE_READ, STORAGE_STAGE);
protected static final Set<String> WRITE_SCOPES = Set.of(STORAGE_CREATE, STORAGE_MODIFY);
protected static final Set<String> ALL_STORAGE_SCOPES =
Sets.newHashSet(STORAGE_READ, STORAGE_MODIFY, STORAGE_CREATE, STORAGE_STAGE);
Set.of(STORAGE_READ, STORAGE_MODIFY, STORAGE_CREATE, STORAGE_STAGE);

public static final String ERROR_INVALID_AUTHENTICATION =
"Invalid authentication: expected a JwtAuthenticationToken object";
Expand All @@ -73,10 +71,10 @@ public class WlcgStructuredPathAuthorizationPdp

public static final String ERROR_UNKNOWN_TOKEN_ISSUER = "Unknown token issuer: %s";

protected static final Set<String> READONLY_METHODS = Sets.newHashSet("GET", "PROPFIND");
protected static final Set<String> REPLACE_METHODS = Sets.newHashSet("PUT", "MKCOL");
protected static final Set<String> MODIFY_METHODS = Sets.newHashSet("PATCH", "DELETE");
protected static final Set<String> CATCHALL_METHODS = Sets.newHashSet("HEAD", "OPTIONS");
protected static final Set<String> READONLY_METHODS = Set.of("GET", "PROPFIND");
protected static final Set<String> REPLACE_METHODS = Set.of("PUT", "MKCOL");
protected static final Set<String> MODIFY_METHODS = Set.of("PATCH", "DELETE");
protected static final Set<String> CATCHALL_METHODS = Set.of("HEAD", "OPTIONS");

public static final String COPY_METHOD = "COPY";
public static final String MOVE_METHOD = "MOVE";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
package org.italiangrid.storm.webdav.authz.vomap;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.isNullOrEmpty;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import org.apache.commons.csv.CSVFormat;
Expand All @@ -31,8 +32,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.Sets;

import eu.emi.security.authn.x509.impl.OpensslNameUtils;

public class MapfileVOMembershipSource implements VOMembershipSource {
Expand All @@ -45,9 +44,9 @@ public class MapfileVOMembershipSource implements VOMembershipSource {

public MapfileVOMembershipSource(String voName, File mapFile) {

checkNotNull(mapFile);
Objects.requireNonNull(mapFile);
checkArgument(!isNullOrEmpty(voName));

this.voName = voName;
this.mapFile = mapFile;

Expand Down Expand Up @@ -83,7 +82,7 @@ public Set<String> getVOMembers() {

long startTime = System.currentTimeMillis();

Set<String> subjects = Sets.newHashSet();
Set<String> subjects = new HashSet<>();

CSVParser parser = getParser();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
package org.italiangrid.storm.webdav.config;

import static com.google.common.collect.Sets.newHashSet;
import static java.util.stream.Collectors.toList;

import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.function.Supplier;

Expand Down Expand Up @@ -93,7 +93,7 @@ Supplier<RequestMatcher> matcherByActionSupplier(Action a, String pattern) {
} else if (Action.DELETE.equals(a)) {
return new AntPathRequestMatcher(pattern, "DELETE");
} else if (Action.LIST.equals(a)) {
return new AndRequestMatcher(new CustomHttpMethodMatcher(newHashSet("PROPFIND")),
return new AndRequestMatcher(new CustomHttpMethodMatcher(Set.of("PROPFIND")),
new AntPathRequestMatcher(pattern));
} else {
throw new IllegalArgumentException("Unknown action: " + a);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/
package org.italiangrid.storm.webdav.config;

import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -27,9 +29,6 @@
import org.italiangrid.storm.webdav.config.validation.Principal;
import org.springframework.validation.annotation.Validated;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

@Validated
public class FineGrainedAuthzPolicyProperties {

Expand All @@ -54,7 +53,7 @@ public enum PrincipalType {

PrincipalType type;

Map<String, String> params = Maps.newHashMap();
Map<String, String> params = new HashMap<>();

public PrincipalType getType() {
return type;
Expand Down Expand Up @@ -89,7 +88,7 @@ public enum Action {
@NotBlank
String sa;

List<String> paths = Lists.newArrayList();
List<String> paths = new ArrayList<>();

@NotEmpty
@Valid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.italiangrid.storm.webdav.config;

import java.util.ArrayList;
import java.util.List;

import javax.validation.constraints.Min;
Expand All @@ -25,8 +26,6 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.annotation.Validated;

import com.google.common.collect.Lists;

@Configuration
@ConfigurationProperties("oauth")
@Validated
Expand All @@ -45,7 +44,7 @@ public static class AuthorizationServer {

boolean enforceAudienceChecks = false;

List<String> audiences = Lists.newArrayList();
List<String> audiences = new ArrayList<>();

public String getName() {
return name;
Expand Down Expand Up @@ -90,7 +89,7 @@ public boolean isEnforceAudienceChecks() {
}

List<AuthorizationServer> issuers;

boolean enableOidc = false;

@Min(value = 1, message = "The refresh period must be a positive integer")
Expand Down Expand Up @@ -126,7 +125,7 @@ public void setRefreshTimeoutSeconds(int refreshTimeoutSeconds) {
public void setEnableOidc(boolean enableOidc) {
this.enableOidc = enableOidc;
}

public boolean isEnableOidc() {
return enableOidc;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.Sets;

public class SAConfigurationParser implements StorageAreaConfiguration {

private static final Set<String> RESERVED_SA_NAMES = Sets.newHashSet("oauth", ".well-known",
"actuator", "assets", "authn-info", "logout", "oidc-login");
private static final Set<String> RESERVED_SA_NAMES =
Set.of("oauth", ".well-known", "actuator", "assets", "authn-info", "logout", "oidc-login");

private final ServiceConfiguration serviceConfig;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.italiangrid.storm.webdav.config.ServiceConfigurationProperties.RedirectorProperties.ReplicaPoolProperties.ReplicaSelectionPolicy.RANDOM;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;

import javax.validation.Valid;
Expand All @@ -31,8 +32,6 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.annotation.Validated;

import com.google.common.collect.Lists;

@Configuration
@ConfigurationProperties("storm")
@Validated
Expand Down Expand Up @@ -127,7 +126,7 @@ public enum ReplicaSelectionPolicy {
}

@NotEmpty
List<ReplicaEndpointProperties> endpoints = Lists.newArrayList();
List<ReplicaEndpointProperties> endpoints = new ArrayList<>();

ReplicaSelectionPolicy policy = RANDOM;

Expand Down Expand Up @@ -230,7 +229,7 @@ public static class AuthorizationProperties {
boolean disabled = false;

@Valid
List<FineGrainedAuthzPolicyProperties> policies = Lists.newArrayList();
List<FineGrainedAuthzPolicyProperties> policies = new ArrayList<>();

public boolean isDisabled() {
return disabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.italiangrid.storm.webdav.fs.attrs;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.isNullOrEmpty;

import java.io.File;
Expand All @@ -27,6 +26,7 @@
import java.nio.file.Path;
import java.nio.file.attribute.UserDefinedFileAttributeView;
import java.util.List;
import java.util.Objects;

public class DefaultExtendedFileAttributesHelper implements
ExtendedAttributesHelper {
Expand Down Expand Up @@ -57,7 +57,7 @@ protected String getAttributeValue(UserDefinedFileAttributeView view,
public void setExtendedFileAttribute(File f, String attributeName,
String attributeValue) throws IOException {

checkNotNull(f);
Objects.requireNonNull(f);
checkArgument(!isNullOrEmpty(attributeName));

UserDefinedFileAttributeView faView = Files.getFileAttributeView(
Expand All @@ -75,7 +75,7 @@ public void setExtendedFileAttribute(File f, String attributeName,
public String getExtendedFileAttributeValue(File f, String attributeName)
throws IOException {

checkNotNull(f);
Objects.requireNonNull(f);
checkArgument(!isNullOrEmpty(attributeName));

UserDefinedFileAttributeView faView = Files.getFileAttributeView(
Expand All @@ -93,7 +93,7 @@ public String getExtendedFileAttributeValue(File f, String attributeName)
@Override
public List<String> getExtendedFileAttributeNames(File f) throws IOException {

checkNotNull(f);
Objects.requireNonNull(f);

UserDefinedFileAttributeView faView = Files.getFileAttributeView(
f.toPath(), UserDefinedFileAttributeView.class);
Expand Down Expand Up @@ -126,7 +126,7 @@ public String getChecksumAttribute(File f) throws IOException {
@Override
public boolean fileSupportsExtendedAttributes(File f) throws IOException {

checkNotNull(f);
Objects.requireNonNull(f);

UserDefinedFileAttributeView faView = Files.getFileAttributeView(
f.toPath(), UserDefinedFileAttributeView.class);
Expand Down
Loading

0 comments on commit 9ae143c

Please sign in to comment.