blob: 9631ab3233497e74f339bdda9cd332c72f46f588 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.security.tls;
import java.util.Set;
/**
* @author bjorncs
*/
public record AuthorizedPeers(Set<PeerPolicy> peerPolicies) {
private static final AuthorizedPeers EMPTY = new AuthorizedPeers(Set.of());
public AuthorizedPeers {
peerPolicies = verifyPeerPolicies(peerPolicies);
}
public static AuthorizedPeers empty() { return EMPTY; }
private static Set<PeerPolicy> verifyPeerPolicies(Set<PeerPolicy> peerPolicies) {
long distinctNames = peerPolicies.stream()
.map(PeerPolicy::policyName)
.distinct()
.count();
if (distinctNames != peerPolicies.size()) {
throw new IllegalArgumentException("'authorized-peers' contains entries with duplicate names");
}
return Set.copyOf(peerPolicies);
}
public boolean isEmpty() { return peerPolicies.isEmpty(); }
}
|