Search in sources :

Example 11 with SignaturTicket

use of se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket in project webcert by sklintyg.

the class SignaturServiceImplTest method userNotAuthorizedClientSignature.

@Test(expected = WebCertServiceException.class)
public void userNotAuthorizedClientSignature() throws IOException {
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(completedUtkast);
    SignaturTicket ticket = intygSignatureService.createDraftHash(INTYG_ID, completedUtkast.getVersion());
    user.setVardgivare(Collections.<Vardgivare>emptyList());
    intygSignatureService.clientSignature(ticket.getId(), "test");
}
Also used : SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) Test(org.junit.Test)

Example 12 with SignaturTicket

use of se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket in project webcert by sklintyg.

the class SignaturTicketTrackerTest method updateStatus.

@Test
public void updateStatus() {
    tracker.trackTicket(new SignaturTicket("id", PAGAENDE_SIG_ID, BEARBETAR, "intygid", 1, LocalDateTime.now(), "1234", LocalDateTime.now()));
    tracker.updateStatus("id", SIGNERAD);
    SignaturTicket tracked = tracker.getTicket("id");
    assertEquals(SIGNERAD, tracked.getStatus());
}
Also used : SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) Test(org.junit.Test)

Example 13 with SignaturTicket

use of se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket in project webcert by sklintyg.

the class SignaturServiceImpl method clientNiasSignature.

@Override
public SignaturTicket clientNiasSignature(String ticketId, SignatureType signatureType, String niasCertificate, 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
    StringWriter sw = new StringWriter();
    JAXB.marshal(signatureType, sw);
    String rawSignaturXml = sw.toString();
    ticket = createAndPersistSignature(utkast, ticket, rawSignaturXml, 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 NIAS 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) StringWriter(java.io.StringWriter) 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 14 with SignaturTicket

use of se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket in project webcert by sklintyg.

the class SignaturTicketTracker method updateStatus.

public synchronized SignaturTicket updateStatus(String id, SignaturTicket.Status status) {
    SignaturTicket ticket = getTicket(id);
    if (ticket != null) {
        LOG.info("Updating status {}", ticket);
        ticket = ticket.withStatus(status);
        ticketMap.put(ticket.getId(), ticket);
    } else {
        LOG.info("Updating status failed, no ticket {}", id);
    }
    return ticket;
}
Also used : SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket)

Example 15 with SignaturTicket

use of se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket 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;
}
Also used : Optional(java.util.Optional) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) OrderResponseType(se.funktionstjanster.grp.v1.OrderResponseType) AuthenticateRequestType(se.funktionstjanster.grp.v1.AuthenticateRequestType) GrpFault(se.funktionstjanster.grp.v1.GrpFault) SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Aggregations

SignaturTicket (se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket)28 Test (org.junit.Test)15 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)12 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)10 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 SignaturTicketResponse (se.inera.intyg.webcert.web.web.controller.moduleapi.dto.SignaturTicketResponse)6 OptimisticLockException (javax.persistence.OptimisticLockException)5 POST (javax.ws.rs.POST)5 OptimisticLockingFailureException (org.springframework.dao.OptimisticLockingFailureException)5 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)3 SignResponse (com.secmaker.netid.nias.v1.SignResponse)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 Optional (java.util.Optional)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Transactional (org.springframework.transaction.annotation.Transactional)1