use of se.inera.intyg.webcert.persistence.utkast.model.Signatur in project webcert by sklintyg.
the class UtkastBootstrapBean method createUtkast.
private Utkast createUtkast(Utlatande json) throws JsonProcessingException {
Utkast utkast = new Utkast();
utkast.setEnhetsId(json.getGrundData().getSkapadAv().getVardenhet().getEnhetsid());
utkast.setEnhetsNamn(json.getGrundData().getSkapadAv().getVardenhet().getEnhetsnamn());
utkast.setIntygsId(json.getId());
utkast.setIntygsTyp(json.getTyp());
utkast.setModel(mapper.writeValueAsString(json));
utkast.setPatientEfternamn(json.getGrundData().getPatient().getEfternamn());
utkast.setPatientFornamn(json.getGrundData().getPatient().getFornamn());
utkast.setPatientMellannamn(json.getGrundData().getPatient().getMellannamn());
utkast.setPatientPersonnummer(json.getGrundData().getPatient().getPersonId());
utkast.setRelationIntygsId(null);
utkast.setRelationKod(null);
// Used for both senastSparadAv and skapadAv
VardpersonReferens vardRef = new VardpersonReferens();
vardRef.setHsaId(json.getGrundData().getSkapadAv().getPersonId());
vardRef.setNamn(json.getGrundData().getSkapadAv().getFullstandigtNamn());
utkast.setSenastSparadAv(vardRef);
utkast.setSkapadAv(vardRef);
utkast.setSignatur(new Signatur(json.getGrundData().getSigneringsdatum(), json.getGrundData().getSkapadAv().getPersonId(), json.getId(), "intygData", "intygHash", "signatur"));
utkast.setStatus(UtkastStatus.SIGNED);
utkast.setSenastSparadDatum(json.getGrundData().getSigneringsdatum());
utkast.setSkickadTillMottagare("FKASSA");
utkast.setSkickadTillMottagareDatum(json.getGrundData().getSigneringsdatum().plusMinutes(2));
utkast.setVardgivarId(json.getGrundData().getSkapadAv().getVardenhet().getVardgivare().getVardgivarid());
utkast.setVardgivarNamn(json.getGrundData().getSkapadAv().getVardenhet().getVardgivare().getVardgivarnamn());
utkast.setVersion(1);
utkast.setVidarebefordrad(false);
return utkast;
}
use of se.inera.intyg.webcert.persistence.utkast.model.Signatur in project webcert by sklintyg.
the class IntygServiceTest method getIntyg.
private Utkast getIntyg(String intygsId, LocalDateTime sendDate, LocalDateTime revokeDate) throws IOException {
String json = IOUtils.toString(new ClassPathResource("FragaSvarServiceImplTest/utlatande.json").getInputStream(), "UTF-8");
Utkast utkast = new Utkast();
utkast.setModel(json);
utkast.setIntygsId(intygsId);
utkast.setIntygsTyp(CERTIFICATE_TYPE);
utkast.setSkickadTillMottagareDatum(sendDate);
utkast.setAterkalladDatum(revokeDate);
utkast.setStatus(UtkastStatus.SIGNED);
utkast.setPatientPersonnummer(PERSNR);
Signatur signatur = new Signatur(LocalDateTime.now(), HSA_ID, CERTIFICATE_ID, "", "", "");
utkast.setSignatur(signatur);
return utkast;
}
use of se.inera.intyg.webcert.persistence.utkast.model.Signatur in project webcert by sklintyg.
the class SignaturServiceImplTest method serverSignatureFailureUniqueIntyg.
@Test
public void serverSignatureFailureUniqueIntyg() {
Feature f = new Feature();
f.setIntygstyper(ImmutableList.of(INTYG_TYPE));
f.setGlobal(true);
user.getFeatures().put(AuthoritiesConstants.FEATURE_UNIKT_INTYG, f);
when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(completedUtkast);
Utkast otherUtkast = createUtkast("otherId", 1L, INTYG_TYPE, UtkastStatus.SIGNED, "", null, "otherEnhet", PERSON_ID);
otherUtkast.setSignatur(new Signatur());
when(mockUtkastRepository.findAllByPatientPersonnummerAndIntygsTypIn(any(String.class), anySet())).thenReturn(ImmutableList.of(otherUtkast));
try {
intygSignatureService.serverSignature(INTYG_ID, completedUtkast.getVersion());
} catch (WebCertServiceException e) {
assertEquals(WebCertServiceErrorCodeEnum.INVALID_STATE_INTYG_EXISTS, e.getErrorCode());
}
}
use of se.inera.intyg.webcert.persistence.utkast.model.Signatur 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.Signatur in project webcert by sklintyg.
the class IntygResource method insertUtkast.
@POST
@Consumes(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
@Produces(MediaType.APPLICATION_JSON)
@Path("/utkast")
public Response insertUtkast(IntygContentWrapper intygContents) throws ModuleNotFoundException, IOException {
String intygsTyp = intygContents.getContents().get("typ").textValue();
String model = intygContents.getContents().toString();
Utlatande utlatande = moduleFacade.getUtlatandeFromInternalModel(intygsTyp, model);
Utkast utkast = new Utkast();
utkast.setModel(model);
utkast.setEnhetsId(utlatande.getGrundData().getSkapadAv().getVardenhet().getEnhetsid());
utkast.setEnhetsNamn(utlatande.getGrundData().getSkapadAv().getVardenhet().getEnhetsnamn());
utkast.setVardgivarId(utlatande.getGrundData().getSkapadAv().getVardenhet().getVardgivare().getVardgivarid());
utkast.setIntygsTyp(utlatande.getTyp());
utkast.setIntygsId(utlatande.getId());
utkast.setPatientEfternamn(utlatande.getGrundData().getPatient().getEfternamn());
utkast.setPatientFornamn(utlatande.getGrundData().getPatient().getFornamn());
utkast.setPatientPersonnummer(utlatande.getGrundData().getPatient().getPersonId());
if (utlatande.getGrundData().getRelation() != null && utlatande.getGrundData().getRelation().getRelationIntygsId() != null) {
if (utlatande.getId() != null && utlatande.getId().equals(utlatande.getGrundData().getRelation().getRelationIntygsId())) {
LOG.error("Utkast relation to itself is invalid.");
} else {
utkast.setRelationIntygsId(utlatande.getGrundData().getRelation().getRelationIntygsId());
utkast.setRelationKod(utlatande.getGrundData().getRelation().getRelationKod());
}
}
utkast.setStatus(intygContents.getUtkastStatus());
utkast.setVidarebefordrad(false);
if (utkast.getStatus() == UtkastStatus.SIGNED) {
Signatur signatur = new Signatur(LocalDateTime.now(), utlatande.getGrundData().getSkapadAv().getPersonId(), utlatande.getId(), model, "ruffel", "fusk");
utkast.setSignatur(signatur);
}
VardpersonReferens vardpersonReferens = new VardpersonReferens();
vardpersonReferens.setHsaId(utlatande.getGrundData().getSkapadAv().getPersonId());
vardpersonReferens.setNamn(utlatande.getGrundData().getSkapadAv().getFullstandigtNamn());
utkast.setSkapadAv(vardpersonReferens);
utkast.setSenastSparadAv(vardpersonReferens);
utkastRepository.save(utkast);
return Response.ok().build();
}
Aggregations