Skip to content

Commit 8a7d3ca

Browse files
committed
Update module 'dcache-common' to use Caffeine.
Signed-off-by: Lukas Mansour <lukas.mansour@desy.de>
1 parent b46704d commit 8a7d3ca

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

modules/common/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
<groupId>com.google.guava</groupId>
2323
<artifactId>guava</artifactId>
2424
</dependency>
25+
<dependency>
26+
<groupId>com.github.ben-manes.caffeine</groupId>
27+
<artifactId>caffeine</artifactId>
28+
</dependency>
2529
<dependency>
2630
<groupId>org.apache.commons</groupId>
2731
<artifactId>commons-math3</artifactId>

modules/common/src/main/java/org/dcache/util/CachingCertificateValidator.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
import static java.util.Collections.singletonList;
2222
import static java.util.Objects.requireNonNull;
2323

24-
import com.google.common.cache.Cache;
25-
import com.google.common.cache.CacheBuilder;
26-
import com.google.common.cache.CacheStats;
24+
import com.github.benmanes.caffeine.cache.Cache;
25+
import com.github.benmanes.caffeine.cache.Caffeine;
26+
import com.github.benmanes.caffeine.cache.stats.CacheStats;
2727
import com.google.common.hash.Hasher;
2828
import com.google.common.hash.Hashing;
2929
import eu.emi.security.authn.x509.ProxySupport;
@@ -39,7 +39,7 @@
3939
import java.security.cert.CertificateExpiredException;
4040
import java.security.cert.CertificateNotYetValidException;
4141
import java.security.cert.X509Certificate;
42-
import java.util.concurrent.ExecutionException;
42+
import java.util.concurrent.CompletionException;
4343
import java.util.concurrent.TimeUnit;
4444

4545
/**
@@ -53,7 +53,7 @@ public class CachingCertificateValidator implements X509CertChainValidatorExt {
5353

5454
public CachingCertificateValidator(X509CertChainValidatorExt val,
5555
long maxCacheEntryLifetime) {
56-
cache = CacheBuilder.newBuilder()
56+
cache = Caffeine.newBuilder()
5757
.expireAfterWrite(maxCacheEntryLifetime, TimeUnit.MILLISECONDS).build();
5858
validator = val;
5959
}
@@ -77,12 +77,12 @@ public ValidationResult validate(final X509Certificate[] certChain) {
7777

7878
String certFingerprint = hasher.hash().toString();
7979

80-
return cache.get(certFingerprint, () -> validator.validate(certChain));
80+
return cache.get(certFingerprint, (key) -> validator.validate(certChain));
8181
} catch (CertificateEncodingException e) {
8282
return new ValidationResult(false, singletonList(
8383
new ValidationError(certChain, pos, ValidationErrorCode.inputError,
8484
e.getMessage())));
85-
} catch (ExecutionException e) {
85+
} catch (CompletionException e) {
8686
return new ValidationResult(false, singletonList(
8787
new ValidationError(certChain, pos, ValidationErrorCode.inputError,
8888
e.getMessage())));

0 commit comments

Comments
 (0)