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;
}
}
}
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);
}
}
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;
}
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"));
}
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));
}
Aggregations