Search in sources :

Example 1 with SignaturTicket

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

the class UtkastModuleApiController method signeraUtkast.

/**
 * Skapa signeringshash.
 *
 * @param intygsId intyg id
 * @return SignaturTicketResponse
 */
@POST
@Path("/{intygsTyp}/{intygsId}/{version}/signeringshash")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public SignaturTicketResponse signeraUtkast(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId, @PathParam("version") long version) {
    authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST).orThrow();
    SignaturTicket ticket;
    try {
        ticket = signaturService.createDraftHash(intygsId, version);
    } catch (OptimisticLockException | OptimisticLockingFailureException e) {
        monitoringLogService.logUtkastConcurrentlyEdited(intygsId, intygsTyp);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.CONCURRENT_MODIFICATION, e.getMessage());
    }
    return new SignaturTicketResponse(ticket);
}
Also used : OptimisticLockingFailureException(org.springframework.dao.OptimisticLockingFailureException) OptimisticLockException(javax.persistence.OptimisticLockException) SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) SignaturTicketResponse(se.inera.intyg.webcert.web.web.controller.moduleapi.dto.SignaturTicketResponse) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 2 with SignaturTicket

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

the class UtkastModuleApiController method biljettStatus.

/**
 * Hamta signeringsstatus.
 *
 * @param biljettId biljett id
 * @return SignaturTicketResponse
 */
@GET
@Path("/{intygsTyp}/{biljettId}/signeringsstatus")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public SignaturTicketResponse biljettStatus(@PathParam("intygsTyp") String intygsTyp, @PathParam("biljettId") String biljettId) {
    authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST).orThrow();
    SignaturTicket ticket = signaturService.ticketStatus(biljettId);
    return new SignaturTicketResponse(ticket);
}
Also used : SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) SignaturTicketResponse(se.inera.intyg.webcert.web.web.controller.moduleapi.dto.SignaturTicketResponse) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with SignaturTicket

use of se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket 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 4 with SignaturTicket

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

the class SignaturServiceImplTest method clientSignatureKOMPLTSuccess.

@Test
public void clientSignatureKOMPLTSuccess() throws IOException, ModuleNotFoundException {
    when(pagaendeSigneringRepository.findOne(anyLong())).thenReturn(pagaendeSignering);
    completedUtkast.setRelationKod(RelationKod.KOMPLT);
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(completedUtkast);
    user.setHsaId("TSTNMT2321000156-1025");
    SignaturTicket ticket = intygSignatureService.createDraftHash(INTYG_ID, completedUtkast.getVersion());
    SignaturTicket status = intygSignatureService.ticketStatus(ticket.getId());
    assertEquals(SignaturTicket.Status.BEARBETAR, status.getStatus());
    String signature = buildSignature();
    when(mockUtkastRepository.save(any(Utkast.class))).thenReturn(completedUtkast);
    // Do the call
    SignaturTicket signatureTicket = intygSignatureService.clientSignature(ticket.getId(), signature);
    verify(intygService).storeIntyg(completedUtkast);
    verify(notificationService).sendNotificationForDraftSigned(any(Utkast.class));
    // Assert pdl log
    verify(logService).logSignIntyg(any(LogRequest.class), isNull());
    assertNotNull(signatureTicket);
    assertNotNull(completedUtkast.getSignatur());
    assertEquals(UtkastStatus.SIGNED, completedUtkast.getStatus());
    // Assert ticket status has changed from BEARBETAR to SIGNERAD
    status = intygSignatureService.ticketStatus(ticket.getId());
    assertEquals(SignaturTicket.Status.SIGNERAD, status.getStatus());
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) Test(org.junit.Test)

Example 5 with SignaturTicket

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

the class SignaturServiceImplTest method clientSignatureSuccess.

@Test
public void clientSignatureSuccess() throws IOException {
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(completedUtkast);
    when(mockUtkastRepository.save(any(Utkast.class))).thenReturn(completedUtkast);
    user.setHsaId("TSTNMT2321000156-1025");
    SignaturTicket ticket = intygSignatureService.createDraftHash(INTYG_ID, completedUtkast.getVersion());
    SignaturTicket status = intygSignatureService.ticketStatus(ticket.getId());
    assertEquals(SignaturTicket.Status.BEARBETAR, status.getStatus());
    String signature = buildSignature();
    // Do the call
    SignaturTicket signatureTicket = intygSignatureService.clientSignature(ticket.getId(), signature);
    verify(intygService).storeIntyg(completedUtkast);
    verify(notificationService).sendNotificationForDraftSigned(any(Utkast.class));
    // Assert pdl log
    verify(logService).logSignIntyg(any(LogRequest.class), isNull());
    assertNotNull(signatureTicket);
    assertNotNull(completedUtkast.getSignatur());
    assertEquals(UtkastStatus.SIGNED, completedUtkast.getStatus());
    // Assert ticket status has changed from BEARBETAR to SIGNERAD
    status = intygSignatureService.ticketStatus(ticket.getId());
    assertEquals(SignaturTicket.Status.SIGNERAD, status.getStatus());
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) Test(org.junit.Test)

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