diff options
-rw-r--r-- | security-utils/src/main/java/com/yahoo/security/tls/policy/AuthorizedPeers.java | 37 | ||||
-rw-r--r-- | security-utils/src/main/java/com/yahoo/security/tls/policy/PeerPolicy.java | 51 |
2 files changed, 9 insertions, 79 deletions
diff --git a/security-utils/src/main/java/com/yahoo/security/tls/policy/AuthorizedPeers.java b/security-utils/src/main/java/com/yahoo/security/tls/policy/AuthorizedPeers.java index 66621224906..136022e2ed9 100644 --- a/security-utils/src/main/java/com/yahoo/security/tls/policy/AuthorizedPeers.java +++ b/security-utils/src/main/java/com/yahoo/security/tls/policy/AuthorizedPeers.java @@ -1,22 +1,18 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.security.tls.policy; -import java.util.Collections; -import java.util.Objects; import java.util.Set; /** * @author bjorncs */ -public class AuthorizedPeers { +public record AuthorizedPeers(Set<PeerPolicy> peerPolicies) { - private final Set<PeerPolicy> peerPolicies; - - public AuthorizedPeers(Set<PeerPolicy> peerPolicies) { - this.peerPolicies = verifyPeerPolicies(peerPolicies); + public AuthorizedPeers { + peerPolicies = verifyPeerPolicies(peerPolicies); } - private Set<PeerPolicy> verifyPeerPolicies(Set<PeerPolicy> peerPolicies) { + private static Set<PeerPolicy> verifyPeerPolicies(Set<PeerPolicy> peerPolicies) { long distinctNames = peerPolicies.stream() .map(PeerPolicy::policyName) .distinct() @@ -24,30 +20,7 @@ public class AuthorizedPeers { if (distinctNames != peerPolicies.size()) { throw new IllegalArgumentException("'authorized-peers' contains entries with duplicate names"); } - return Collections.unmodifiableSet(peerPolicies); - } - - public Set<PeerPolicy> peerPolicies() { - return peerPolicies; - } - - @Override - public String toString() { - return "AuthorizedPeers{" + - "peerPolicies=" + peerPolicies + - '}'; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - AuthorizedPeers that = (AuthorizedPeers) o; - return Objects.equals(peerPolicies, that.peerPolicies); + return Set.copyOf(peerPolicies); } - @Override - public int hashCode() { - return Objects.hash(peerPolicies); - } } diff --git a/security-utils/src/main/java/com/yahoo/security/tls/policy/PeerPolicy.java b/security-utils/src/main/java/com/yahoo/security/tls/policy/PeerPolicy.java index ff518622f53..332c0d1a43f 100644 --- a/security-utils/src/main/java/com/yahoo/security/tls/policy/PeerPolicy.java +++ b/security-utils/src/main/java/com/yahoo/security/tls/policy/PeerPolicy.java @@ -1,62 +1,19 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.security.tls.policy; -import java.util.Collections; import java.util.List; -import java.util.Objects; import java.util.Optional; /** * @author bjorncs */ -public class PeerPolicy { - - private final String policyName; - private final String description; - private final List<RequiredPeerCredential> requiredCredentials; +public record PeerPolicy(String policyName, Optional<String> description, List<RequiredPeerCredential> requiredCredentials) { public PeerPolicy(String policyName, List<RequiredPeerCredential> requiredCredentials) { - this(policyName, null, requiredCredentials); - } - - public PeerPolicy( - String policyName, String description, List<RequiredPeerCredential> requiredCredentials) { - this.policyName = policyName; - this.description = description; - this.requiredCredentials = Collections.unmodifiableList(requiredCredentials); - } - - public String policyName() { - return policyName; - } - - public Optional<String> description() { return Optional.ofNullable(description); } - - public List<RequiredPeerCredential> requiredCredentials() { - return requiredCredentials; - } - - @Override - public String toString() { - return "PeerPolicy{" + - "policyName='" + policyName + '\'' + - ", description='" + description + '\'' + - ", requiredCredentials=" + requiredCredentials + - '}'; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - PeerPolicy that = (PeerPolicy) o; - return Objects.equals(policyName, that.policyName) && - Objects.equals(description, that.description) && - Objects.equals(requiredCredentials, that.requiredCredentials); + this(policyName, Optional.empty(), List.copyOf(requiredCredentials)); } - @Override - public int hashCode() { - return Objects.hash(policyName, description, requiredCredentials); + public PeerPolicy(String policyName, String description, List<RequiredPeerCredential> requiredCredentials) { + this(policyName, Optional.ofNullable(description), List.copyOf(requiredCredentials)); } } |