Search in sources :

Example 81 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.

the class IntygServiceImpl method verifyEnhetsAuth.

protected void verifyEnhetsAuth(Utlatande utlatande, boolean isReadOnlyOperation) {
    Vardenhet vardenhet = utlatande.getGrundData().getSkapadAv().getVardenhet();
    if (!webCertUserService.isAuthorizedForUnit(vardenhet.getVardgivare().getVardgivarid(), vardenhet.getEnhetsid(), isReadOnlyOperation)) {
        String msg = "User not authorized for enhet " + vardenhet.getEnhetsid();
        LOG.debug(msg);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, msg);
    }
}
Also used : Vardenhet(se.inera.intyg.common.support.model.common.internal.Vardenhet) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 82 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.

the class IntygServiceImpl method sendIntygToCertificateSender.

protected IntygServiceResult sendIntygToCertificateSender(SendIntygConfiguration sendConfig, Utlatande intyg, boolean delay) {
    String intygsId = intyg.getId();
    String recipient = sendConfig.getRecipient();
    String intygsTyp = intyg.getTyp();
    HoSPersonal skickatAv = IntygConverterUtil.buildHosPersonalFromWebCertUser(webCertUserService.getUser(), null);
    try {
        LOG.debug("Sending intyg {} of type {} to recipient {}", intygsId, intygsTyp, recipient);
        // Ask the certificateSenderService to post a 'send' message onto the queue.
        certificateSenderService.sendCertificate(intygsId, intyg.getGrundData().getPatient().getPersonId(), objectMapper.writeValueAsString(skickatAv), recipient, delay);
        // Notify stakeholders when a certificate is sent
        notificationService.sendNotificationForIntygSent(intygsId);
        return IntygServiceResult.OK;
    } catch (WebServiceException wse) {
        LOG.error("An WebServiceException occured when trying to send intyg: " + intygsId, wse);
        return IntygServiceResult.FAILED;
    } catch (RuntimeException e) {
        LOG.error("Module problems occured when trying to send intyg " + intygsId, e);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, e);
    } catch (JsonProcessingException e) {
        LOG.error("Error writing skickatAv as string when trying to send intyg " + intygsId, e);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, e);
    } catch (CertificateSenderException e) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, e);
    }
}
Also used : HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) WebServiceException(javax.xml.ws.WebServiceException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) CertificateSenderException(se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderException)

Example 83 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.

the class SignaturServiceImpl method getWebcertUserForSignering.

private WebCertUser getWebcertUserForSignering() {
    IntygUser user = webCertUserService.getUser();
    AuthoritiesValidator authoritiesValidator = new AuthoritiesValidator();
    if (!authoritiesValidator.given(user).privilege(AuthoritiesConstants.PRIVILEGE_SIGNERA_INTYG).isVerified()) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, "User is not a doctor. Could not sign utkast.");
    }
    return (WebCertUser) user;
}
Also used : IntygUser(se.inera.intyg.infra.security.common.model.IntygUser) AuthoritiesValidator(se.inera.intyg.infra.security.authorities.validation.AuthoritiesValidator) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 84 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.

the class SignaturServiceImpl method finalizeClientSignature.

private SignaturTicket finalizeClientSignature(String ticketId, String rawSignatur, WebCertUser user) {
    // Lookup signature ticket
    SignaturTicket ticket = ticketTracker.getTicket(ticketId);
    if (ticket == null) {
        LOG.warn("Ticket '{}' hittades ej", ticketId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Biljett " + ticketId + " hittades ej");
    }
    LOG.debug("Klientsignering ticket '{}' intyg '{}'", ticket.getId(), ticket.getIntygsId());
    // Fetch the draft
    Utkast utkast = getUtkastForSignering(ticket.getIntygsId(), ticket.getVersion(), user);
    // Create and persist the new signature
    ticket = createAndPersistSignature(utkast, ticket, rawSignatur, user);
    monitoringService.logIntygSigned(utkast.getIntygsId(), utkast.getIntygsTyp(), user.getHsaId(), user.getAuthenticationScheme(), utkast.getRelationKod());
    // Notify stakeholders when certificate has been signed
    notificationService.sendNotificationForDraftSigned(utkast);
    LogRequest logRequest = LogRequestFactory.createLogRequestFromUtkast(utkast);
    // Note that we explictly supplies the WebCertUser here. The BankID finalization is not executed in a HTTP
    // request context and thus we need to supply the user instance manually.
    logService.logSignIntyg(logRequest, logService.getLogUser(user));
    intygService.handleAfterSigned(utkast);
    return ticketTracker.updateStatus(ticket.getId(), SignaturTicket.Status.SIGNERAD);
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 85 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.

the class SignaturServiceImpl method createSignaturTicket.

private SignaturTicket createSignaturTicket(String intygId, long pagaendeSigneringInternreferens, long version, String payload, LocalDateTime signeringstid) {
    try {
        String hash = createHash(payload);
        String id = UUID.randomUUID().toString();
        SignaturTicket statusTicket = new SignaturTicket(id, pagaendeSigneringInternreferens, SignaturTicket.Status.BEARBETAR, intygId, version, signeringstid, hash, LocalDateTime.now());
        ticketTracker.trackTicket(statusTicket);
        return statusTicket;
    } catch (IllegalStateException e) {
        LOG.error("Error occured when generating signing hash for intyg {}: {}", intygId, e);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.UNKNOWN_INTERNAL_PROBLEM, "Internal error signing intyg " + intygId + ", problem when creating signing ticket", e);
    }
}
Also used : SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Aggregations

WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)85 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)35 Test (org.junit.Test)16 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)16 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)14 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)14 Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)13 OptimisticLockException (javax.persistence.OptimisticLockException)12 MedicinsktArende (se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende)11 Personnummer (se.inera.intyg.schemas.contract.Personnummer)10 SignaturTicket (se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket)10 Path (javax.ws.rs.Path)9 Produces (javax.ws.rs.Produces)9 SekretessStatus (se.inera.intyg.webcert.common.model.SekretessStatus)9 OptimisticLockingFailureException (org.springframework.dao.OptimisticLockingFailureException)7 Transactional (org.springframework.transaction.annotation.Transactional)7 POST (javax.ws.rs.POST)6 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)6 Signatur (se.inera.intyg.webcert.persistence.utkast.model.Signatur)6 LocalDateTime (java.time.LocalDateTime)5