@Test public void receiveSignatureResponse() throws IOException { var stream = new ClassPathResource("dss/signResponse.xml").getInputStream(); var string = new BufferedReader(new InputStreamReader(stream)).lines().collect(Collectors.joining("\n")); String relayState = "0ff25a22-d78a-46c0-ae78-58e34b62ce90"; dssSignatureService.receiveSignResponse(relayState, string); verify(underskriftService).netidSignature(ticketIdCaptor.capture(), signatureCaptor.capture(), certificateCaptor.capture()); assertEquals(ticketIdCaptor.getValue(), "0ff25a22-d78a-46c0-ae78-58e34b62ce90"); var certByteArray = "MIILpjCCCo6gAwIBAgIILGNiAxjmjgowDQYJKoZIhvcNAQELBQAwgYMxOTA3BgNVBAMMMENHSSBTdmVyaWdlIEFCIFNUIFN1YnN0YW50aWFsIERTUyBFbmQgVXNlciBDQSB2MjEdMBsGA1UECwwURFNTIEVuZCBVc2VyIFNpZ25pbmcxGjAYBgNVBAoMEUNHSSBTdmVyaWdlIEFCIFNUMQswCQYDVQQGEwJTRTAeFw0yMDA1MDcwNDA5NDdaFw0yMTA1MDcxMDAzMzNaMFMxDzANBgNVBCoMBkFuZHJldzEQMA4GA1UEBAwHRGlsbGFyZDEVMBMGA1UEBRMMMTk2NzA3MTgzMTMwMRcwFQYDVQQDDA5BbmRyZXcgRGlsbGFyZDBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABE2xWh+y5JLNUYMG69z7feKgXKnK1UIzP6yiaFVofi2RHONk8+Bg9rSX1g5Og65BurXk+2JNv6UwPd9MOk4ShUujggkWMIIJEjAMBgNVHRMBAf8EAjAAME0GA1UdHwRGMEQwQqBAoD6GPGh0dHA6Ly9lc2lnbi52Mi5zdC5zaWduYXR1cmVzZXJ2aWNlLnNlL3Rlc3RDQVN1YnN0YW50aWFsLmNybDAdBgNVHQ4EFgQUtU4TPRik8Zvy1lRTXsP80YfM1AIwHwYDVR0jBBgwFoAU3VXF2mDN4t1bNOpUiJzA4h8SfrswGAYDVR0gBBEwDzANBgsrBgEEAYH1fgMIAjAOBgNVHQ8BAf8EBAMCBkAwg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3ontsoEyl/UBLQ=="; assertEquals(certificateCaptor.getValue(), certByteArray); var signByteArray = Base64.getDecoder() .decode("MEYCIQDexXhdoTJWwjcXnQUGR2QAXcEbP+5N1f8QPghNeGb2dgIhAOvoNNfTlZqPyhuuYwLryVirmx/90NHsWf+oefZEQjBd"); assertEquals(Arrays.toString(signatureCaptor.getValue()), Arrays.toString(signByteArray)); }
@SuppressWarnings("unchecked") public SignaturBiljett receiveSignResponse(String relayState, String eIdSignResponse) { SignResponse signResponse; try { signResponse = unMarshallSignResponse(eIdSignResponse); var result = signResponse.getResult(); var resultMajor = result.getResultMajor(); if (RESULTMAJOR_SUCCESS.equals(resultMajor)) { var signTasks = (JAXBElement<SignTasksType>) signResponse.getSignatureObject().getOther().getAny().get(0); var signTaskDataType = signTasks.getValue().getSignTaskData().get(0); byte[] signature = signTaskDataType.getBase64Signature() .getValue(); var signResponseExtension = (JAXBElement<SignResponseExtensionType>) signResponse.getOptionalOutputs().getAny().get(0); var certificates = signResponseExtension.getValue().getSignatureCertificateChain().getX509Certificate(); var certificate = findFirstCertificateInChain(certificates); return underskriftService.netidSignature(relayState, signature, certificate); } else { var resultMinor = result.getResultMinor(); var resultMessage = result.getResultMessage() == null ? null : result.getResultMessage().getValue(); SignaturBiljett signaturBiljett = redisTicketTracker.updateStatus(relayState, SignaturStatus.ERROR); monitoringLogService .logSignServiceErrorReceived(relayState, signaturBiljett.getIntygsId(), resultMajor, resultMinor, resultMessage); return signaturBiljett; } } catch (JAXBException e) { SignaturBiljett signaturBiljett = redisTicketTracker.updateStatus(relayState, SignaturStatus.ERROR); monitoringLogService .logSignResponseInvalid(relayState, signaturBiljett.getIntygsId(), "Could not unmarshal sign response: " + e.getMessage()); return signaturBiljett; } catch (Exception e) { SignaturBiljett signaturBiljett = redisTicketTracker.updateStatus(relayState, SignaturStatus.ERROR); monitoringLogService .logSignResponseInvalid(relayState, signaturBiljett.getIntygsId(), "Internal problem: " + e.getMessage()); return signaturBiljett; } }
DssSignatureService { @SuppressWarnings("unchecked") public SignaturBiljett receiveSignResponse(String relayState, String eIdSignResponse) { SignResponse signResponse; try { signResponse = unMarshallSignResponse(eIdSignResponse); var result = signResponse.getResult(); var resultMajor = result.getResultMajor(); if (RESULTMAJOR_SUCCESS.equals(resultMajor)) { var signTasks = (JAXBElement<SignTasksType>) signResponse.getSignatureObject().getOther().getAny().get(0); var signTaskDataType = signTasks.getValue().getSignTaskData().get(0); byte[] signature = signTaskDataType.getBase64Signature() .getValue(); var signResponseExtension = (JAXBElement<SignResponseExtensionType>) signResponse.getOptionalOutputs().getAny().get(0); var certificates = signResponseExtension.getValue().getSignatureCertificateChain().getX509Certificate(); var certificate = findFirstCertificateInChain(certificates); return underskriftService.netidSignature(relayState, signature, certificate); } else { var resultMinor = result.getResultMinor(); var resultMessage = result.getResultMessage() == null ? null : result.getResultMessage().getValue(); SignaturBiljett signaturBiljett = redisTicketTracker.updateStatus(relayState, SignaturStatus.ERROR); monitoringLogService .logSignServiceErrorReceived(relayState, signaturBiljett.getIntygsId(), resultMajor, resultMinor, resultMessage); return signaturBiljett; } } catch (JAXBException e) { SignaturBiljett signaturBiljett = redisTicketTracker.updateStatus(relayState, SignaturStatus.ERROR); monitoringLogService .logSignResponseInvalid(relayState, signaturBiljett.getIntygsId(), "Could not unmarshal sign response: " + e.getMessage()); return signaturBiljett; } catch (Exception e) { SignaturBiljett signaturBiljett = redisTicketTracker.updateStatus(relayState, SignaturStatus.ERROR); monitoringLogService .logSignResponseInvalid(relayState, signaturBiljett.getIntygsId(), "Internal problem: " + e.getMessage()); return signaturBiljett; } } }
DssSignatureService { @SuppressWarnings("unchecked") public SignaturBiljett receiveSignResponse(String relayState, String eIdSignResponse) { SignResponse signResponse; try { signResponse = unMarshallSignResponse(eIdSignResponse); var result = signResponse.getResult(); var resultMajor = result.getResultMajor(); if (RESULTMAJOR_SUCCESS.equals(resultMajor)) { var signTasks = (JAXBElement<SignTasksType>) signResponse.getSignatureObject().getOther().getAny().get(0); var signTaskDataType = signTasks.getValue().getSignTaskData().get(0); byte[] signature = signTaskDataType.getBase64Signature() .getValue(); var signResponseExtension = (JAXBElement<SignResponseExtensionType>) signResponse.getOptionalOutputs().getAny().get(0); var certificates = signResponseExtension.getValue().getSignatureCertificateChain().getX509Certificate(); var certificate = findFirstCertificateInChain(certificates); return underskriftService.netidSignature(relayState, signature, certificate); } else { var resultMinor = result.getResultMinor(); var resultMessage = result.getResultMessage() == null ? null : result.getResultMessage().getValue(); SignaturBiljett signaturBiljett = redisTicketTracker.updateStatus(relayState, SignaturStatus.ERROR); monitoringLogService .logSignServiceErrorReceived(relayState, signaturBiljett.getIntygsId(), resultMajor, resultMinor, resultMessage); return signaturBiljett; } } catch (JAXBException e) { SignaturBiljett signaturBiljett = redisTicketTracker.updateStatus(relayState, SignaturStatus.ERROR); monitoringLogService .logSignResponseInvalid(relayState, signaturBiljett.getIntygsId(), "Could not unmarshal sign response: " + e.getMessage()); return signaturBiljett; } catch (Exception e) { SignaturBiljett signaturBiljett = redisTicketTracker.updateStatus(relayState, SignaturStatus.ERROR); monitoringLogService .logSignResponseInvalid(relayState, signaturBiljett.getIntygsId(), "Internal problem: " + e.getMessage()); return signaturBiljett; } } @Autowired  DssSignatureService(DssMetadataService dssMetadataService, DssSignMessageService dssSignMessageService,
        WebCertUserService userService, UtkastRepository utkastRepository, UnderskriftService underskriftService,
        RedisTicketTracker redisTicketTracker, MonitoringLogService monitoringLogService, IntygModuleRegistry moduleRegistry); }
DssSignatureService { @SuppressWarnings("unchecked") public SignaturBiljett receiveSignResponse(String relayState, String eIdSignResponse) { SignResponse signResponse; try { signResponse = unMarshallSignResponse(eIdSignResponse); var result = signResponse.getResult(); var resultMajor = result.getResultMajor(); if (RESULTMAJOR_SUCCESS.equals(resultMajor)) { var signTasks = (JAXBElement<SignTasksType>) signResponse.getSignatureObject().getOther().getAny().get(0); var signTaskDataType = signTasks.getValue().getSignTaskData().get(0); byte[] signature = signTaskDataType.getBase64Signature() .getValue(); var signResponseExtension = (JAXBElement<SignResponseExtensionType>) signResponse.getOptionalOutputs().getAny().get(0); var certificates = signResponseExtension.getValue().getSignatureCertificateChain().getX509Certificate(); var certificate = findFirstCertificateInChain(certificates); return underskriftService.netidSignature(relayState, signature, certificate); } else { var resultMinor = result.getResultMinor(); var resultMessage = result.getResultMessage() == null ? null : result.getResultMessage().getValue(); SignaturBiljett signaturBiljett = redisTicketTracker.updateStatus(relayState, SignaturStatus.ERROR); monitoringLogService .logSignServiceErrorReceived(relayState, signaturBiljett.getIntygsId(), resultMajor, resultMinor, resultMessage); return signaturBiljett; } } catch (JAXBException e) { SignaturBiljett signaturBiljett = redisTicketTracker.updateStatus(relayState, SignaturStatus.ERROR); monitoringLogService .logSignResponseInvalid(relayState, signaturBiljett.getIntygsId(), "Could not unmarshal sign response: " + e.getMessage()); return signaturBiljett; } catch (Exception e) { SignaturBiljett signaturBiljett = redisTicketTracker.updateStatus(relayState, SignaturStatus.ERROR); monitoringLogService .logSignResponseInvalid(relayState, signaturBiljett.getIntygsId(), "Internal problem: " + e.getMessage()); return signaturBiljett; } } @Autowired  DssSignatureService(DssMetadataService dssMetadataService, DssSignMessageService dssSignMessageService,
        WebCertUserService userService, UtkastRepository utkastRepository, UnderskriftService underskriftService,
        RedisTicketTracker redisTicketTracker, MonitoringLogService monitoringLogService, IntygModuleRegistry moduleRegistry); boolean isUnitInIeWhitelist(String currentCareUnitHsaId); DssSignRequestDTO createSignatureRequestDTO(SignaturBiljett sb); String createTransactionID(); @SuppressWarnings("unchecked") SignaturBiljett receiveSignResponse(String relayState, String eIdSignResponse); String findReturnErrorUrl(String intygsId, String ticketId); String findReturnUrl(String intygsId); SignaturBiljett updateSignatureTicketWithError(String relayState); }
DssSignatureService { @SuppressWarnings("unchecked") public SignaturBiljett receiveSignResponse(String relayState, String eIdSignResponse) { SignResponse signResponse; try { signResponse = unMarshallSignResponse(eIdSignResponse); var result = signResponse.getResult(); var resultMajor = result.getResultMajor(); if (RESULTMAJOR_SUCCESS.equals(resultMajor)) { var signTasks = (JAXBElement<SignTasksType>) signResponse.getSignatureObject().getOther().getAny().get(0); var signTaskDataType = signTasks.getValue().getSignTaskData().get(0); byte[] signature = signTaskDataType.getBase64Signature() .getValue(); var signResponseExtension = (JAXBElement<SignResponseExtensionType>) signResponse.getOptionalOutputs().getAny().get(0); var certificates = signResponseExtension.getValue().getSignatureCertificateChain().getX509Certificate(); var certificate = findFirstCertificateInChain(certificates); return underskriftService.netidSignature(relayState, signature, certificate); } else { var resultMinor = result.getResultMinor(); var resultMessage = result.getResultMessage() == null ? null : result.getResultMessage().getValue(); SignaturBiljett signaturBiljett = redisTicketTracker.updateStatus(relayState, SignaturStatus.ERROR); monitoringLogService .logSignServiceErrorReceived(relayState, signaturBiljett.getIntygsId(), resultMajor, resultMinor, resultMessage); return signaturBiljett; } } catch (JAXBException e) { SignaturBiljett signaturBiljett = redisTicketTracker.updateStatus(relayState, SignaturStatus.ERROR); monitoringLogService .logSignResponseInvalid(relayState, signaturBiljett.getIntygsId(), "Could not unmarshal sign response: " + e.getMessage()); return signaturBiljett; } catch (Exception e) { SignaturBiljett signaturBiljett = redisTicketTracker.updateStatus(relayState, SignaturStatus.ERROR); monitoringLogService .logSignResponseInvalid(relayState, signaturBiljett.getIntygsId(), "Internal problem: " + e.getMessage()); return signaturBiljett; } } @Autowired  DssSignatureService(DssMetadataService dssMetadataService, DssSignMessageService dssSignMessageService,
        WebCertUserService userService, UtkastRepository utkastRepository, UnderskriftService underskriftService,
        RedisTicketTracker redisTicketTracker, MonitoringLogService monitoringLogService, IntygModuleRegistry moduleRegistry); boolean isUnitInIeWhitelist(String currentCareUnitHsaId); DssSignRequestDTO createSignatureRequestDTO(SignaturBiljett sb); String createTransactionID(); @SuppressWarnings("unchecked") SignaturBiljett receiveSignResponse(String relayState, String eIdSignResponse); String findReturnErrorUrl(String intygsId, String ticketId); String findReturnUrl(String intygsId); SignaturBiljett updateSignatureTicketWithError(String relayState); static final String RESULTMAJOR_SUCCESS; static final String REQUESTED_SIGN_ALGORITHM; }