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