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

[master] fix: always generate a new code for email factor #5441

Merged
merged 1 commit into from
Feb 7, 2025
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 @@ -29,6 +29,7 @@
import io.gravitee.am.model.factor.EnrolledFactor;
import io.gravitee.am.model.factor.EnrolledFactorChannel;
import io.gravitee.am.model.factor.EnrolledFactorSecurity;
import io.gravitee.am.model.factor.FactorStatus;
import io.gravitee.am.repository.exceptions.TechnicalException;
import io.gravitee.am.resource.api.ResourceProvider;
import io.gravitee.am.resource.api.email.EmailSenderProvider;
Expand Down Expand Up @@ -122,9 +123,10 @@ private Completable generateCodeAndSendEmail(FactorContext context, EmailSenderP
EmailService emailService = context.getComponent(EmailService.class);

// Code Expiration date is present, that mean the code has not been validated
// check if the code has expired to know if we have to generate a new code or send the same
if (enrolledFactor.getSecurity().getData(FactorDataKeys.KEY_EXPIRE_AT, Long.class) != null &&
Instant.now().isAfter(Instant.ofEpochMilli(enrolledFactor.getSecurity().getData(FactorDataKeys.KEY_EXPIRE_AT, Long.class)))) {
// check if the code has expired to know if we have to generate a new code for PENDING factor
final var expireAt = enrolledFactor.getSecurity().getData(FactorDataKeys.KEY_EXPIRE_AT, Long.class);
final var codeExpired = expireAt != null && Instant.now().isAfter(Instant.ofEpochMilli(expireAt));
if (enrolledFactor.getStatus() != FactorStatus.PENDING_ACTIVATION || codeExpired) {
incrementMovingFactor(enrolledFactor);
}

Expand Down