Skip to content

Commit

Permalink
fix: always generate a new code for email factor
Browse files Browse the repository at this point in the history
fixes AM-4734
  • Loading branch information
leleueri committed Feb 7, 2025
1 parent f411465 commit 75b4c8e
Showing 1 changed file with 5 additions and 3 deletions.
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

0 comments on commit 75b4c8e

Please sign in to comment.