Class EmailVerificationService
java.lang.Object
com.svenruppert.jsentinel.accountlifecycle.EmailVerificationService
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:
request(subject, email, ttl)— generates a plain token, persists only its hash with the email it confirms, emitsEmailVerificationRequested, hands the plain token to theJSentinelNotificationSender.validate(plain)— looks the token up; returns the record only when live, in this tenant, not consumed, not expired.consume(plain)— marks the token consumed exactly once and emitsEmailVerified.
Bound to one TenantId at construction.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordTuple returned fromrequest: the plain token (caller forwards it via the notification sender) and the persisted record (handy for tests / audit hooks). -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault token entropy in bytes (256 bits). -
Constructor Summary
ConstructorsConstructorDescriptionEmailVerificationService(EmailVerificationTokenStore store, PasswordHasher hasher, JSentinelAuditService auditService, JSentinelNotificationSender notificationSender) Convenience constructor: tenantTenantId.DEFAULT, system clock, 256-bit token source.EmailVerificationService(EmailVerificationTokenStore store, PasswordHasher hasher, JSentinelAuditService auditService, JSentinelNotificationSender notificationSender, TenantId tenant, Clock clock, Supplier<String> tokenSource) Full constructor. -
Method Summary
Modifier and TypeMethodDescriptionMarks the token consumed exactly once, emitsEmailVerifiedand aJSentinelNotification.Kind.EMAIL_VERIFIEDnotification.intPurges every expired record in the backing store.Issues a verification token forsubjectId/email.intDrops every token issued tosubjectIdin this service's tenant.Validates a candidate plain token.
-
Field Details
-
DEFAULT_TOKEN_BYTES
public static final int DEFAULT_TOKEN_BYTESDefault token entropy in bytes (256 bits).- See Also:
-
-
Constructor Details
-
EmailVerificationService
public EmailVerificationService(EmailVerificationTokenStore store, PasswordHasher hasher, JSentinelAuditService auditService, JSentinelNotificationSender notificationSender) Convenience constructor: tenantTenantId.DEFAULT, system clock, 256-bit token source.- Parameters:
store- backing token store; non-nullhasher- password hasher used to hash tokens; non-nullauditService- audit sink; non-nullnotificationSender- notification dispatcher; non-null
-
EmailVerificationService
public EmailVerificationService(EmailVerificationTokenStore store, PasswordHasher hasher, JSentinelAuditService auditService, JSentinelNotificationSender notificationSender, TenantId tenant, Clock clock, Supplier<String> tokenSource) Full constructor.- Parameters:
store- backing token store; non-nullhasher- password hasher used to hash tokens; non-nullauditService- audit sink; non-nullnotificationSender- notification dispatcher; non-nulltenant- tenant scope;nullbecomesTenantId.DEFAULTclock- time source; non-nulltokenSource- plain-token supplier; non-null, non-blank
-
-
Method Details
-
request
public EmailVerificationService.IssuedToken request(SubjectId subjectId, String email, Duration ttl) Issues a verification token forsubjectId/email.- Parameters:
subjectId- subject whose email is being verified; non-nullemail- email address being verified; non-blankttl- token lifetime; strictly positive- Returns:
- issued token (plain value + persisted record)
-
validate
Validates a candidate plain token. Live records only.- Parameters:
plainToken- plain token; null/blank yields empty- Returns:
- matching live record, if any
-
consume
Marks the token consumed exactly once, emitsEmailVerifiedand aJSentinelNotification.Kind.EMAIL_VERIFIEDnotification.- Parameters:
plainToken- plain token; null/blank yields empty- Returns:
- consumed record on the successful transition, empty otherwise
-
revokeAll
Drops every token issued tosubjectIdin 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
-