use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException 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.common.service.exception.WebCertServiceException in project webcert by sklintyg.
the class GrpSignaturServiceImpl method startGrpAuthentication.
@Override
public SignaturTicket startGrpAuthentication(String intygId, long version) {
Utkast utkast = utkastRepository.findOne(intygId);
validateUtkast(intygId, utkast);
WebCertUser webCertUser = webCertUserService.getUser();
validateWebCertUser(webCertUser);
String personId = webCertUser.getPersonId();
validatePersonId(personId);
SignaturTicket draftHash = signaturService.createDraftHash(intygId, utkast.getVersion());
AuthenticateRequestType authRequest = buildAuthRequest(personId, draftHash);
OrderResponseType orderResponse;
try {
orderResponse = grpService.authenticate(authRequest);
} catch (GrpFault grpFault) {
signaturTicketTracker.updateStatus(draftHash.getId(), SignaturTicket.Status.OKAND);
Optional<FaultStatusType> status = Optional.ofNullable(grpFault.getFaultInfo()).map(GrpFaultType::getFaultStatus);
if (status.isPresent()) {
LOG.warn("Fault signing utkast with id {} with GRP. FaultStatus: {}", intygId, status.get().name());
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.GRP_PROBLEM, status.get().name());
} else {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.UNKNOWN_INTERNAL_PROBLEM, grpFault.getMessage());
}
}
// If we could init the authentication, we create a SignaturTicket, reusing
// the mechanism already present for SITHS
String orderRef = orderResponse.getOrderRef();
String transactionId = validateOrderResponseTxId(authRequest, orderResponse);
startAsyncCollectPoller(orderRef, transactionId);
return draftHash;
}
use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.
the class ArendeServiceImpl method openArendeAsUnhandled.
@Override
public ArendeConversationView openArendeAsUnhandled(String meddelandeId) {
Arende arende = lookupArende(meddelandeId);
boolean arendeIsAnswered = !arendeRepository.findBySvarPaId(meddelandeId).isEmpty();
// Enforce business rule FS-011, from FK + answer should remain closed
if (!FrageStallare.WEBCERT.isKodEqual(arende.getSkickatAv()) && arendeIsAnswered) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "FS-011: Cant revert status for question " + meddelandeId);
}
NotificationEvent notificationEvent = determineNotificationEvent(arende, arendeIsAnswered);
if (arendeIsAnswered) {
arende.setStatus(Status.ANSWERED);
} else {
if (FrageStallare.WEBCERT.isKodEqual(arende.getSkickatAv())) {
arende.setStatus(Status.PENDING_EXTERNAL_ACTION);
} else {
arende.setStatus(Status.PENDING_INTERNAL_ACTION);
}
}
Arende openedArende = arendeRepository.save(arende);
sendNotification(openedArende, notificationEvent);
return arendeViewConverter.convertToArendeConversationView(openedArende, arendeRepository.findBySvarPaId(meddelandeId).stream().findFirst().orElse(null), null, arendeRepository.findByPaminnelseMeddelandeId(meddelandeId), null);
}
use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.
the class ArendeServiceImpl method processIncomingMessage.
@Override
public Arende processIncomingMessage(Arende arende) {
if (arendeRepository.findOneByMeddelandeId(arende.getMeddelandeId()) != null) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "meddelandeId not unique");
}
Utkast utkast = utkastRepository.findOne(arende.getIntygsId());
validateArende(arende.getIntygsId(), utkast);
ArendeConverter.decorateArendeFromUtkast(arende, utkast, LocalDateTime.now(systemClock), hsaEmployeeService);
updateRelated(arende);
monitoringLog.logArendeReceived(arende.getIntygsId(), utkast.getIntygsTyp(), utkast.getEnhetsId(), arende.getAmne(), arende.getKomplettering().stream().map(MedicinsktArende::getFrageId).collect(Collectors.toList()), arende.getSvarPaId() != null);
Arende saved = arendeRepository.save(arende);
if (ArendeAmne.PAMINN == saved.getAmne() || saved.getSvarPaId() == null) {
notificationService.sendNotificationForQuestionReceived(saved);
} else {
notificationService.sendNotificationForAnswerRecieved(saved);
}
return saved;
}
use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.
the class IntygModuleApiControllerTest method testCreateNewRenewWithCopyOkParamFalse.
@Test
public void testCreateNewRenewWithCopyOkParamFalse() {
// Given
final boolean copyOk = false;
final String intygsTyp = "fk7263";
setupUser(AuthoritiesConstants.PRIVILEGE_FORNYA_INTYG, intygsTyp, true, copyOk, AuthoritiesConstants.FEATURE_FORNYA_INTYG);
// When
try {
moduleApiController.createRenewal(new CopyIntygRequest(), intygsTyp, "");
} catch (WebCertServiceException wcse) {
// Then an exception is thrown
assertEquals(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, wcse.getErrorCode());
assertEquals("Authorization failed due to false kopieraOK-parameter", wcse.getMessage());
return;
}
fail("No or wrong exception was thrown");
}
Aggregations