Search in sources :

Example 26 with WebCertServiceException

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

the class IntygIntegrationController method handleRedirectToIntyg.

Response handleRedirectToIntyg(UriInfo uriInfo, String intygTyp, String intygId, String enhetId, WebCertUser user) {
    try {
        // Call service
        PrepareRedirectToIntyg prepareRedirectInfo = integrationService.prepareRedirectToIntyg(intygTyp, intygId, user);
        // Persist reference
        handleReference(intygId, user.getParameters().getReference());
        if (Strings.nullToEmpty(enhetId).trim().isEmpty()) {
            if (userHasExactlyOneSelectableVardenhet(user)) {
                user.changeValdVardenhet(user.getVardgivare().get(0).getVardenheter().get(0).getId());
                updateUserWithActiveFeatures(user);
                LOG.debug("Redirecting to view intyg {} of type {}", intygId, intygTyp);
                return buildRedirectResponse(uriInfo, prepareRedirectInfo);
            }
            // Set state parameter telling us that we have been redirected to 'enhetsvaljaren'
            user.getParameters().getState().setRedirectToEnhetsval(true);
            LOG.warn("Deep integration request does not contain an 'enhet', redirecting to enhet selection page!");
            return buildChooseUnitResponse(uriInfo, prepareRedirectInfo);
        } else {
            if (user.changeValdVardenhet(enhetId)) {
                updateUserWithActiveFeatures(user);
                LOG.debug("Redirecting to view intyg {} of type {}", intygId, intygTyp);
                return buildRedirectResponse(uriInfo, prepareRedirectInfo);
            }
            LOG.warn("Validation failed for deep-integration request because user {} is not authorized for enhet {}", user.getHsaId(), enhetId);
            return buildAuthorizedErrorResponse(uriInfo);
        }
    } catch (WebCertServiceException e) {
        if (e.getErrorCode().equals(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND)) {
            LOG.error(e.getMessage());
            return buildNoContentErrorResponse(uriInfo);
        } else {
            throw e;
        }
    }
}
Also used : PrepareRedirectToIntyg(se.inera.intyg.webcert.web.web.controller.integration.dto.PrepareRedirectToIntyg) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 27 with WebCertServiceException

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

the class IntygIntegrationController method getDestinationUrl.

private String getDestinationUrl(UriInfo uriInfo, PrepareRedirectToIntyg prepareRedirectToIntyg) {
    String intygId = prepareRedirectToIntyg.getIntygId();
    String intygTyp = prepareRedirectToIntyg.getIntygTyp();
    String urlPath = String.format("/visa/intyg/%s/%s/resume", intygTyp, intygId);
    try {
        // get the builder without any existing query params
        UriBuilder uriBuilder = uriInfo.getRequestUriBuilder().replacePath(urlPath).replaceQuery(null);
        URI uri = uriBuilder.build();
        return URLEncoder.encode(uri.toString(), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.UNKNOWN_INTERNAL_PROBLEM, e);
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 28 with WebCertServiceException

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

the class NiasSignaturServiceImpl method startNiasAuthentication.

@Override
public SignaturTicket startNiasAuthentication(String intygId, long version) {
    Utkast utkast = utkastRepository.findOne(intygId);
    validateUtkast(intygId, utkast);
    WebCertUser webCertUser = webCertUserService.getUser();
    validateWebCertUser(webCertUser);
    // Try to use personnummer. If not possible, use hsaId instead. This is a temporary hack for testing.
    String personId = webCertUser.getPersonId() != null ? webCertUser.getPersonId() : webCertUser.getHsaId();
    // validatePersonId(personId);
    SignaturTicket draftHash = signaturService.createDraftHash(intygId, utkast.getVersion());
    // För NetID Access Server signering så behöver vi göra en XMLDSig signatur
    // inklusive en ordentlig digest av canoniserad XML.
    // Börja med att konvertera intyget till XML-format
    // String xml = utkastModelToXmlConverterService.utkastToXml(utkast);
    // SignatureType signatureType = xmldSigService.prepareSignature(xml);
    byte[] digestValue = "temp".getBytes(Charset.forName("UTF-8"));
    SignResponse response;
    try {
        String result = netiDAccessServerSoap.sign(personId, "Inera Webcert: Signera intyg " + utkast.getIntygsId(), new String(digestValue, Charset.forName("UTF-8")), null);
        response = JAXB.unmarshal(new StringReader(result), SignResponse.class);
    } catch (Exception ex) {
        signaturTicketTracker.updateStatus(draftHash.getId(), SignaturTicket.Status.OKAND);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.UNKNOWN_INTERNAL_PROBLEM, ex.getMessage());
    }
    // If we could init the authentication, we create a SignaturTicket, reusing
    // the mechanism already present for SITHS
    String orderRef = response.getSignResult();
    startAsyncNiasCollectPoller(orderRef, draftHash.getId(), new SignatureType());
    return draftHash;
}
Also used : SignResponse(com.secmaker.netid.nias.v1.SignResponse) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) StringReader(java.io.StringReader) SignatureType(se.inera.intyg.infra.xmldsig.model.SignatureType) SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 29 with WebCertServiceException

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

the class IntegrationServiceImpl method verifySekretessmarkering.

void verifySekretessmarkering(Utkast utkast, WebCertUser user) {
    SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(utkast.getPatientPersonnummer());
    if (SekretessStatus.UNDEFINED.equals(sekretessStatus)) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Could not fetch sekretesstatus for patient from PU service");
    }
    authoritiesValidator.given(user, utkast.getIntygsTyp()).privilegeIf(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, sekretessStatus == SekretessStatus.TRUE).orThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING, "User missing required privilege or cannot handle sekretessmarkerad patient"));
}
Also used : SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 30 with WebCertServiceException

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

the class IntegrationServiceImpl method prepareRedirectToIntyg.

// api
@Override
public PrepareRedirectToIntyg prepareRedirectToIntyg(String intygTyp, String intygId, WebCertUser user) {
    Utkast utkast = utkastRepository.findOne(intygId);
    // INTYG-4336: If intygTyp can't be established,
    // fetch certificate from IT and then get the type
    String typ = resolveIntygsTyp(intygTyp, intygId, utkast);
    if (StringUtils.isEmpty(typ)) {
        String msg = "Failed resolving type of certificate";
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, msg);
    }
    ensurePreparation(typ, intygId, utkast, user);
    return createPrepareRedirectToIntyg(typ, intygId, isUtkast(utkast));
}
Also used : Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) 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