Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1803: Ensure the getOperation doesn't change operation status #1804

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -763,11 +763,10 @@ public OperationDetailResponse operationDetail(OperationDetailRequest request) t
});

final String userId = request.getUserId();
final OperationEntity operationEntity = expireOperation(
claimOperation(operation, userId, currentTimestamp),
currentTimestamp
);
final OperationEntity operationEntity =
claimOperation(operation, userId, currentTimestamp);
final OperationDetailResponse operationDetailResponse = convertFromEntityAndFillOtp(operationEntity);
markOperationExpired(operationDetailResponse, currentTimestamp);
extendAndSetOperationDetailData(operationDetailResponse);
return operationDetailResponse;
} catch (GenericServiceException ex) {
Expand Down Expand Up @@ -1013,6 +1012,17 @@ private OperationEntity expireOperation(OperationEntity operationEntity, Date cu
return operationEntity;
}

private void markOperationExpired(OperationDetailResponse operation, Date currentTimestamp) throws GenericServiceException {
// Operation is still pending and timestamp is after the expiration.
if (OperationStatus.PENDING.equals(operation.getStatus())
&& operation.getTimestampExpires().before(currentTimestamp)) {
// Operation status is persisted only using background service to avoid database deadlocks,
// because two concurrent UPDATE queries can be executed at the same time.
// The status in the database may be updated few seconds later for this reason.
operation.setStatus(OperationStatus.EXPIRED);
}
}

private boolean factorsAcceptable(@NotNull OperationEntity operation, PowerAuthSignatureTypes usedFactor) {
final String operationId = operation.getId();
final PowerAuthSignatureTypes[] allowedFactors = operation.getSignatureType();
Expand Down
Loading