Class EmailVerificationService

java.lang.Object
com.svenruppert.jsentinel.accountlifecycle.EmailVerificationService

@ExperimentalJSentinelApi public final class EmailVerificationService extends Object
Email-verification workflow over an EmailVerificationTokenStore.

Mirrors PasswordResetService but carries the verified email address on the record (a password-reset record has no such field). Three-step lifecycle:

  1. request(subject, email, ttl) — generates a plain token, persists only its hash with the email it confirms, emits EmailVerificationRequested, hands the plain token to the JSentinelNotificationSender.
  2. validate(plain) — looks the token up; returns the record only when live, in this tenant, not consumed, not expired.
  3. consume(plain) — marks the token consumed exactly once and emits EmailVerified.

Bound to one TenantId at construction.

  • Field Details

    • DEFAULT_TOKEN_BYTES

      public static final int DEFAULT_TOKEN_BYTES
      Default token entropy in bytes (256 bits).
      See Also:
  • Constructor Details

  • Method Details

    • request

      public EmailVerificationService.IssuedToken request(SubjectId subjectId, String email, Duration ttl)
      Issues a verification token for subjectId / email.
      Parameters:
      subjectId - subject whose email is being verified; non-null
      email - email address being verified; non-blank
      ttl - token lifetime; strictly positive
      Returns:
      issued token (plain value + persisted record)
    • validate

      public Optional<EmailVerificationTokenRecord> validate(String plainToken)
      Validates a candidate plain token. Live records only.
      Parameters:
      plainToken - plain token; null/blank yields empty
      Returns:
      matching live record, if any
    • consume

      public Optional<EmailVerificationTokenRecord> consume(String plainToken)
      Marks the token consumed exactly once, emits EmailVerified and a JSentinelNotification.Kind.EMAIL_VERIFIED notification.
      Parameters:
      plainToken - plain token; null/blank yields empty
      Returns:
      consumed record on the successful transition, empty otherwise
    • revokeAll

      public int revokeAll(SubjectId subjectId)
      Drops every token issued to subjectId in this service's tenant.
      Parameters:
      subjectId - subject; non-null
      Returns:
      number of tokens removed
    • purgeExpired

      public int purgeExpired()
      Purges every expired record in the backing store. Spans all tenants.
      Returns:
      number of records purged