use of se.inera.intyg.webcert.persistence.utkast.model.PagaendeSignering in project webcert by sklintyg.
the class PagaendeSigneringCleanupServiceImplTest method testCleanupKeepAll.
@Test
public void testCleanupKeepAll() {
List<PagaendeSignering> list = new ArrayList<>();
PagaendeSignering ps1 = buildOngoingSignature("1", 1L, LocalDateTime.now().minusMinutes(7));
PagaendeSignering ps2 = buildOngoingSignature("2", 2L, LocalDateTime.now().minusMinutes(5));
list.add(ps1);
list.add(ps2);
when(pagaendeSigneringRepository.findAll()).thenReturn(list);
testee.cleanup();
verify(pagaendeSigneringRepository, times(0)).delete(anyLong());
}
use of se.inera.intyg.webcert.persistence.utkast.model.PagaendeSignering in project webcert by sklintyg.
the class PagaendeSigneringCleanupServiceImplTest method testCleanupOneKeepOne.
@Test
public void testCleanupOneKeepOne() {
List<PagaendeSignering> list = new ArrayList<>();
PagaendeSignering ps1 = buildOngoingSignature("1", 1L, LocalDateTime.now().minusMinutes(20));
PagaendeSignering ps2 = buildOngoingSignature("2", 2L, LocalDateTime.now().minusMinutes(5));
list.add(ps1);
list.add(ps2);
when(pagaendeSigneringRepository.findAll()).thenReturn(list);
testee.cleanup();
verify(pagaendeSigneringRepository, times(1)).delete(anyLong());
}
use of se.inera.intyg.webcert.persistence.utkast.model.PagaendeSignering in project webcert by sklintyg.
the class SignaturServiceImpl method createDraftHash.
/**
* Called from the Controller when initiating a client (e.g. NetID) signature. Rewritten in INTYG-5048 so
* <i>starting</i> a signature process does NOT mutate the Utkast in any way. Instead, a temporary intyg JSON model
* including the signatureDate and signing identity is stored in a {@link PagaendeSignering} entity.
* <p>
* Once the signing has been completed
* (see {@link SignaturServiceImpl#createAndPersistSignature(Utkast, SignaturTicket, String, WebCertUser)}) the
* hash, intygsId and version from the JSON model in the PagaendeSignatur is validated and if everything works out,
* the final state is written to the Utkast table.
* <p>
* If the user for some reason failed to finish the signing (cancelled in NetID etc.), the Utkast table won't be
* affected or contain a signingDate even though it wasn't signed. A stale entry may remain in PAGAENDE_SIGNERING
* but since those cannot be reused such entries can remain there indefinitely or until cleaned up by a janitor
* task.
*
* @param intygId The id of the draft to generate signing ticket for
* @param version version
* @return
*/
@Override
@Transactional("jpaTransactionManager")
public SignaturTicket createDraftHash(String intygId, long version) {
LOG.debug("Hash for clientsignature of draft '{}'", intygId);
// Fetch Webcert user
WebCertUser user = getWebcertUserForSignering();
// Fetch the certificate draft
Utkast utkast = getUtkastForSignering(intygId, version, user);
LocalDateTime signeringstid = LocalDateTime.now();
try {
VardpersonReferens vardpersonReferens = UpdateUserUtil.createVardpersonFromWebCertUser(user);
ModuleApi moduleApi = moduleRegistry.getModuleApi(utkast.getIntygsTyp());
Vardenhet vardenhetFromJson = moduleApi.getUtlatandeFromJson(utkast.getModel()).getGrundData().getSkapadAv().getVardenhet();
String updatedInternal = moduleApi.updateBeforeSigning(utkast.getModel(), IntygConverterUtil.buildHosPersonalFromWebCertUser(user, vardenhetFromJson), signeringstid);
// Skapa ny PagaendeSignering
PagaendeSignering pagaendeSignering = new PagaendeSignering();
pagaendeSignering.setIntygData(updatedInternal);
pagaendeSignering.setIntygsId(utkast.getIntygsId());
pagaendeSignering.setSigneradAvHsaId(vardpersonReferens.getHsaId());
pagaendeSignering.setSigneradAvNamn(vardpersonReferens.getNamn());
pagaendeSignering.setSigneringsDatum(signeringstid);
pagaendeSignering = pagaendeSigneringRepository.save(pagaendeSignering);
return createSignaturTicket(utkast.getIntygsId(), pagaendeSignering.getInternReferens(), utkast.getVersion(), updatedInternal, signeringstid);
} catch (ModuleNotFoundException | IOException | ModuleException e) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Unable to sign certificate: " + e.getMessage());
}
}
use of se.inera.intyg.webcert.persistence.utkast.model.PagaendeSignering in project webcert by sklintyg.
the class SignaturServiceImpl method createAndPersistSignature.
private SignaturTicket createAndPersistSignature(Utkast utkast, SignaturTicket ticket, String rawSignature, WebCertUser user) {
validateUniqueIntyg(user, utkast.getIntygsTyp(), utkast.getPatientPersonnummer());
PagaendeSignering pagaendeSignering = pagaendeSigneringRepository.findOne(ticket.getPagaendeSigneringId());
if (pagaendeSignering == null) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Can't complete signing of certificate, no PagaendeSignering found for interreferens " + ticket.getPagaendeSigneringId());
}
String payload = pagaendeSignering.getIntygData();
if (!pagaendeSignering.getIntygsId().equals(utkast.getIntygsId())) {
LOG.error("Signing of utkast '{}' failed since the intygsId ({}) on the Utkast is different from the one " + "on the signing operation ({})", utkast.getIntygsId(), pagaendeSignering.getIntygsId());
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Internal error signing utkast, the payload of utkast " + utkast.getIntygsId() + " has been modified since signing was initialized");
}
if (!ticket.getHash().equals(createHash(payload))) {
LOG.error("Signing of utkast '{}' failed since the payload has been modified since signing was initialized", utkast.getIntygsId());
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Internal error signing utkast, the payload of utkast " + utkast.getIntygsId() + " has been modified since signing was initialized");
}
if (utkast.getVersion() != ticket.getVersion()) {
LOG.error("Signing of utkast '{}' failed since the version on the utkast ({}) differs from when the signing was initialized ({})", utkast.getIntygsId(), utkast.getVersion(), ticket.getVersion());
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.CONCURRENT_MODIFICATION, "Cannot complete signing, Utkast version differs from signature ticket version.");
}
Signatur signatur = new Signatur(ticket.getSigneringstid(), user.getHsaId(), ticket.getIntygsId(), payload, ticket.getHash(), rawSignature);
// Update user information ("senast sparat av")
// Add signature to the utkast and set status as signed
utkast.setSenastSparadAv(new VardpersonReferens(pagaendeSignering.getSigneradAvHsaId(), pagaendeSignering.getSigneradAvNamn()));
utkast.setModel(payload);
utkast.setSignatur(signatur);
utkast.setStatus(UtkastStatus.SIGNED);
// Persist utkast with added signature
Utkast savedUtkast = utkastRepository.save(utkast);
// Send to Intygstjanst
intygService.storeIntyg(savedUtkast);
// Remove PagaendeSignering
pagaendeSigneringRepository.delete(ticket.getPagaendeSigneringId());
return ticket;
}
use of se.inera.intyg.webcert.persistence.utkast.model.PagaendeSignering in project webcert by sklintyg.
the class PagaendeSigneringCleanupServiceImplTest method buildOngoingSignature.
private PagaendeSignering buildOngoingSignature(String intygsId, long internReferens, LocalDateTime signeringsDatum) {
PagaendeSignering ps1 = new PagaendeSignering();
ps1.setIntygsId(intygsId);
ps1.setInternReferens(internReferens);
ps1.setSigneringsDatum(signeringsDatum);
return ps1;
}
Aggregations