Search in sources :

Example 1 with GrpFault

use of se.funktionstjanster.grp.v1.GrpFault in project webcert by sklintyg.

the class GrpCollectPollerImpl method run.

@Override
public void run() {
    try {
        applySecurityContextToThreadLocal();
        WebCertUser webCertUser = (WebCertUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        long startTimeMs = System.currentTimeMillis();
        while ((startTimeMs + TIMEOUT) > System.currentTimeMillis()) {
            CollectRequestType req = buildCollectRequest();
            try {
                CollectResponseType resp = grpService.collect(req);
                LOG.info("GRP collect returned ProgressStatusType: {}", resp.getProgressStatus());
                switch(resp.getProgressStatus()) {
                    case COMPLETE:
                        String subjectSerialNumber = getCollectResponseAttribute(resp.getAttributes());
                        if (!subjectSerialNumber.replaceAll("\\-", "").equals(webCertUser.getPersonId().replaceAll("\\-", ""))) {
                            throw new IllegalStateException("Could not process GRP Collect COMPLETE response, subject serialNumber did not match " + "issuing WebCertUser.");
                        }
                        String signature = resp.getSignature();
                        signaturService.clientGrpSignature(resp.getTransactionId(), signature, webCertUser);
                        LOG.info("Signature was successfully persisted and ticket updated.");
                        return;
                    case USER_SIGN:
                        signaturTicketTracker.updateStatus(transactionId, SignaturTicket.Status.VANTA_SIGN);
                        break;
                    case OUTSTANDING_TRANSACTION:
                    case STARTED:
                    case USER_REQ:
                        break;
                    case NO_CLIENT:
                        signaturTicketTracker.updateStatus(transactionId, SignaturTicket.Status.NO_CLIENT);
                        LOG.info("GRP collect returned ProgressStatusType: {}, " + "has the user started their BankID or Mobilt BankID application?", resp.getProgressStatus());
                        break;
                }
            } catch (GrpFault grpFault) {
                handleGrpFault(grpFault);
                // Always terminate loop after a GrpFault has been encountered
                return;
            }
            sleepMs(ms);
        }
    } finally {
        // Since this poller thread will be returned to its thread pool, we make sure we clean up the security
        // context we bound to this runnable's threadlocal.
        SecurityContextHolder.clearContext();
    }
}
Also used : CollectResponseType(se.funktionstjanster.grp.v1.CollectResponseType) GrpFault(se.funktionstjanster.grp.v1.GrpFault) CollectRequestType(se.funktionstjanster.grp.v1.CollectRequestType) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 2 with GrpFault

use of se.funktionstjanster.grp.v1.GrpFault 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)

Example 3 with GrpFault

use of se.funktionstjanster.grp.v1.GrpFault in project webcert by sklintyg.

the class GrpCollectPollerTest method buildFault.

private GrpFault buildFault(FaultStatusType faultStatusType) {
    GrpFaultType grpFaultType = new GrpFaultType();
    grpFaultType.setFaultStatus(faultStatusType);
    grpFaultType.setDetailedDescription("detailed-desc");
    GrpFault fault = new GrpFault("", grpFaultType);
    return fault;
}
Also used : GrpFaultType(se.funktionstjanster.grp.v1.GrpFaultType) GrpFault(se.funktionstjanster.grp.v1.GrpFault)

Example 4 with GrpFault

use of se.funktionstjanster.grp.v1.GrpFault in project webcert by sklintyg.

the class GrpSignaturServiceTest method testAuthenticateRequestThrowsExceptionWhenGrpCallFails.

@Test(expected = RuntimeException.class)
public void testAuthenticateRequestThrowsExceptionWhenGrpCallFails() throws GrpFault {
    when(webCertUserService.getUser()).thenReturn(webCertUser);
    when(utkastRepository.findOne(INTYG_ID)).thenReturn(buildUtkast());
    when(signaturService.createDraftHash(INTYG_ID, VERSION)).thenReturn(buildSignaturTicket());
    when(grpService.authenticate(any(AuthenticateRequestType.class))).thenThrow(new GrpFault("grp-fault"));
    try {
        grpSignaturService.startGrpAuthentication(INTYG_ID, VERSION);
    } finally {
        verify(signaturTicketTracker, times(1)).updateStatus(TX_ID, SignaturTicket.Status.OKAND);
        verify(taskExecutor, times(0)).execute(any(GrpCollectPoller.class), any(Long.class));
    }
}
Also used : AuthenticateRequestType(se.funktionstjanster.grp.v1.AuthenticateRequestType) GrpFault(se.funktionstjanster.grp.v1.GrpFault) Test(org.junit.Test)

Aggregations

GrpFault (se.funktionstjanster.grp.v1.GrpFault)4 AuthenticateRequestType (se.funktionstjanster.grp.v1.AuthenticateRequestType)2 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)2 Optional (java.util.Optional)1 Test (org.junit.Test)1 CollectRequestType (se.funktionstjanster.grp.v1.CollectRequestType)1 CollectResponseType (se.funktionstjanster.grp.v1.CollectResponseType)1 GrpFaultType (se.funktionstjanster.grp.v1.GrpFaultType)1 OrderResponseType (se.funktionstjanster.grp.v1.OrderResponseType)1 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)1 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)1 SignaturTicket (se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket)1