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 1 commit
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);
expireOperation(operationDetailResponse,currentTimestamp);
banterCZ marked this conversation as resolved.
Show resolved Hide resolved
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 expireOperation(OperationDetailResponse operation, Date currentTimestamp) throws GenericServiceException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not duplicate this logic, we can reuse the code below in new private method shared by both expireOperation methods and call it to obtain status.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method changes only the response class, not the entity. I suggest to rename it to avoid confusion.

// 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