@@ -291,33 +291,22 @@ private RevocationInfo request(OcspService ocspService, X509Certificate subjectC
291291 responseTime = Instant .now ();
292292 requestDuration = Duration .between (requestTime , responseTime );
293293 RevocationInfo revocationInfo = getRevocationInfo (ocspResponderUri , e , request , null , requestDuration , responseTime );
294- revocationInfo .ocspResponseAttributes ().put (RevocationInfo .KEY_OCSP_RESPONSE , e .getResponseBody ());
295- revocationInfo .ocspResponseAttributes ().put (RevocationInfo .KEY_HTTP_STATUS_CODE , e .getStatusCode ());
294+ revocationInfo = revocationInfo
295+ .withOcspResponse (e .getResponseBody ())
296+ .withHttpStatusCode (e .getStatusCode ());
296297 throw new ResilientUserCertificateOCSPCheckFailedException (new ValidationInfo (subjectCertificate , List .of (revocationInfo )));
297298 }
298299 if (response .getStatus () != OCSPResponseStatus .SUCCESSFUL ) {
299300 ResilientUserCertificateOCSPCheckFailedException exception = new ResilientUserCertificateOCSPCheckFailedException ("Response status: " + ocspStatusToString (response .getStatus ()));
300- RevocationInfo revocationInfo = new RevocationInfo (ocspService .getAccessLocation (), new HashMap <>(Map .ofEntries (
301- Map .entry (RevocationInfo .KEY_OCSP_ERROR , exception ),
302- Map .entry (RevocationInfo .KEY_OCSP_REQUEST , request ),
303- Map .entry (RevocationInfo .KEY_OCSP_RESPONSE , response ),
304- Map .entry (RevocationInfo .KEY_REQUEST_DURATION , requestDuration ),
305- Map .entry (RevocationInfo .KEY_OCSP_RESPONSE_TIME , responseTime )
306- )));
301+ RevocationInfo revocationInfo = getRevocationInfo (ocspResponderUri , exception , request , response , requestDuration , responseTime );
307302 exception .setValidationInfo (new ValidationInfo (subjectCertificate , List .of (revocationInfo )));
308303 throw exception ;
309304 }
310305
311306 final BasicOCSPResp basicResponse = (BasicOCSPResp ) response .getResponseObject ();
312307 if (basicResponse == null ) {
313308 ResilientUserCertificateOCSPCheckFailedException exception = new ResilientUserCertificateOCSPCheckFailedException ("Missing Basic OCSP Response" );
314- RevocationInfo revocationInfo = new RevocationInfo (ocspService .getAccessLocation (), new HashMap <>(Map .ofEntries (
315- Map .entry (RevocationInfo .KEY_OCSP_ERROR , exception ),
316- Map .entry (RevocationInfo .KEY_OCSP_REQUEST , request ),
317- Map .entry (RevocationInfo .KEY_OCSP_RESPONSE , response ),
318- Map .entry (RevocationInfo .KEY_REQUEST_DURATION , requestDuration ),
319- Map .entry (RevocationInfo .KEY_OCSP_RESPONSE_TIME , responseTime )
320- )));
309+ RevocationInfo revocationInfo = getRevocationInfo (ocspResponderUri , exception , request , response , requestDuration , responseTime );
321310 exception .setValidationInfo (new ValidationInfo (subjectCertificate , List .of (revocationInfo )));
322311 throw exception ;
323312 }
@@ -329,12 +318,7 @@ private RevocationInfo request(OcspService ocspService, X509Certificate subjectC
329318 }
330319 LOG .debug ("OCSP response verified successfully" );
331320
332- return new RevocationInfo (ocspResponderUri ,new HashMap <>( Map .ofEntries (
333- Map .entry (RevocationInfo .KEY_OCSP_REQUEST , request ),
334- Map .entry (RevocationInfo .KEY_OCSP_RESPONSE , response ),
335- Map .entry (RevocationInfo .KEY_REQUEST_DURATION , requestDuration ),
336- Map .entry (RevocationInfo .KEY_OCSP_RESPONSE_TIME , responseTime )
337- )));
321+ return getRevocationInfo (ocspResponderUri , null , request , response , requestDuration , responseTime );
338322 } catch (ResilientUserCertificateOCSPCheckFailedException e ) {
339323 throw e ;
340324 } catch (UserCertificateRevokedException e ) {
@@ -355,20 +339,23 @@ private RevocationInfo request(OcspService ocspService, X509Certificate subjectC
355339
356340 private RevocationInfo getRevocationInfo (URI ocspResponderUri , Exception e , OCSPReq request , OCSPResp response ,
357341 Duration requestDuration , Instant end ) {
358- RevocationInfo revocationInfo = new RevocationInfo (ocspResponderUri , new HashMap <>(Map .of (RevocationInfo .KEY_OCSP_ERROR , e )));
342+ Map <String , Object > ocspResponseAttributes = new HashMap <>();
343+ if (e != null ) {
344+ ocspResponseAttributes .put (RevocationInfo .KEY_OCSP_ERROR , e );
345+ }
359346 if (request != null ) {
360- revocationInfo . ocspResponseAttributes () .put (RevocationInfo .KEY_OCSP_REQUEST , request );
347+ ocspResponseAttributes .put (RevocationInfo .KEY_OCSP_REQUEST , request );
361348 }
362349 if (response != null ) {
363- revocationInfo . ocspResponseAttributes () .put (RevocationInfo .KEY_OCSP_RESPONSE , response );
350+ ocspResponseAttributes .put (RevocationInfo .KEY_OCSP_RESPONSE , response );
364351 }
365352 if (requestDuration != null ) {
366- revocationInfo . ocspResponseAttributes () .put (RevocationInfo .KEY_REQUEST_DURATION , requestDuration );
353+ ocspResponseAttributes .put (RevocationInfo .KEY_REQUEST_DURATION , requestDuration );
367354 }
368355 if (end != null ) {
369- revocationInfo . ocspResponseAttributes () .put (RevocationInfo .KEY_OCSP_RESPONSE_TIME , end );
356+ ocspResponseAttributes .put (RevocationInfo .KEY_OCSP_RESPONSE_TIME , end );
370357 }
371- return revocationInfo ;
358+ return new RevocationInfo ( ocspResponderUri , ocspResponseAttributes ) ;
372359 }
373360
374361 private static CircuitBreakerConfig getCircuitBreakerConfig (CircuitBreakerConfig circuitBreakerConfig ) {
0 commit comments