Skip to content

Commit f544ee4

Browse files
committed
AUT-2547 Add support for two fallbacks
1 parent e9e6fb9 commit f544ee4

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/main/java/eu/webeid/ocsp/service/OcspServiceProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,7 @@ public OcspService getService(X509Certificate certificate) throws AuthTokenExcep
7676
return new AiaOcspService(aiaOcspServiceConfiguration, certificate, fallbackOcspService);
7777
}
7878

79+
public FallbackOcspService getFallbackService(URI ocspServiceUri) {
80+
return fallbackOcspServiceMap.get(ocspServiceUri);
81+
}
7982
}

src/main/java/eu/webeid/resilientocsp/ResilientOcspCertificateRevocationChecker.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,29 @@ public List<RevocationInfo> validateCertificateNotRevoked(X509Certificate subjec
118118
circuitBreaker.getEventPublisher().onError(event -> createAndAddRevocationInfoToList(event.getThrowable(), revocationInfoList));
119119

120120
CheckedFunction0<RevocationInfo> primarySupplier = () -> request(ocspService, subjectCertificate, issuerCertificate, false);
121-
CheckedFunction0<RevocationInfo> fallbackSupplier = () -> request(ocspService.getFallbackService(), subjectCertificate, issuerCertificate, true);
121+
OcspService firstFallbackService = ocspService.getFallbackService();
122+
CheckedFunction0<RevocationInfo> firstFallbackSupplier = () -> request(ocspService.getFallbackService(), subjectCertificate, issuerCertificate, true);
123+
OcspService secondFallbackService = getOcspServiceProvider().getFallbackService(firstFallbackService.getAccessLocation());
124+
CheckedFunction0<RevocationInfo> fallbackSupplier;
125+
if (secondFallbackService == null) {
126+
fallbackSupplier = firstFallbackSupplier;
127+
} else {
128+
CheckedFunction0<RevocationInfo> secondFallbackSupplier = () -> request(secondFallbackService, subjectCertificate, issuerCertificate, true);
129+
fallbackSupplier = () -> {
130+
try {
131+
return firstFallbackSupplier.apply();
132+
} catch (Exception e) {
133+
if (e instanceof ResilientUserCertificateOCSPCheckFailedException exception) {
134+
revocationInfoList.addAll((exception.getValidationInfo().revocationInfoList()));
135+
} else {
136+
revocationInfoList.add(new RevocationInfo(null, Map.ofEntries(
137+
Map.entry(RevocationInfo.KEY_OCSP_ERROR, e)
138+
)));
139+
}
140+
return secondFallbackSupplier.apply();
141+
}
142+
};
143+
}
122144
Decorators.DecorateCheckedSupplier<RevocationInfo> decorateCheckedSupplier = Decorators.ofCheckedSupplier(primarySupplier);
123145
if (retryRegistry != null) {
124146
Retry retry = retryRegistry.retry(ocspService.getAccessLocation().toASCIIString());

0 commit comments

Comments
 (0)