Package io.meeds.social.security.plugin
Class EmailOtpPlugin
java.lang.Object
io.meeds.social.security.plugin.EmailOtpPlugin
- All Implemented Interfaces:
io.meeds.web.security.plugin.OtpPlugin
- Direct Known Subclasses:
AccountDeactivationEmailOtpPlugin,UserAccountEmailOtpPlugin
@Service
public class EmailOtpPlugin
extends Object
implements io.meeds.web.security.plugin.OtpPlugin
Generates, caches and validates email OTP codes: the code is stored under a
purpose-bound cache key (
getCacheKey(String)) and the email is sent
through the common BrandedEmailSender with a per-plugin content
fragment and subject key.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanconsumeOtp(String userName, String otpCode) Removes the code from the cache, so that it never validates again.voidgenerateOtpCode(String userName) protected StringgetCacheKey(String userName) Key under which the OTP code of a user is stored, distinct by plugin so that a code generated for one purpose can never validate another onelongprotected StringgetName()longprotected booleanWhether a wrong code lifts the send lock of this method.booleanvalidateOtp(String userName, String otpCode) A wrong code keeps the send lock, unless the method releases it (releasesSendLockOnWrongCode()): the user then may ask for a new code at once instead of waiting out the send interval, bounded by the attempts the validating service counts per code
-
Constructor Details
-
EmailOtpPlugin
public EmailOtpPlugin()
-
-
Method Details
-
getName
- Specified by:
getNamein interfaceio.meeds.web.security.plugin.OtpPlugin
-
canUse
- Specified by:
canUsein interfaceio.meeds.web.security.plugin.OtpPlugin
-
validateOtp
A wrong code keeps the send lock, unless the method releases it (releasesSendLockOnWrongCode()): the user then may ask for a new code at once instead of waiting out the send interval, bounded by the attempts the validating service counts per code- Specified by:
validateOtpin interfaceio.meeds.web.security.plugin.OtpPlugin
-
releasesSendLockOnWrongCode
protected boolean releasesSendLockOnWrongCode()Whether a wrong code lifts the send lock of this method. False here: the email change, API key and account deactivation flows keep waiting out the send interval after a wrong code -
consumeOtp
Removes the code from the cache, so that it never validates again. Only the request that removes it wins: a concurrent one finds it gone.- Specified by:
consumeOtpin interfaceio.meeds.web.security.plugin.OtpPlugin
-
getCodeTtlMinutes
public long getCodeTtlMinutes()- Specified by:
getCodeTtlMinutesin interfaceio.meeds.web.security.plugin.OtpPlugin
-
getSendIntervalSeconds
public long getSendIntervalSeconds()- Specified by:
getSendIntervalSecondsin interfaceio.meeds.web.security.plugin.OtpPlugin
-
generateOtpCode
- Specified by:
generateOtpCodein interfaceio.meeds.web.security.plugin.OtpPlugin
-
getCacheKey
Key under which the OTP code of a user is stored, distinct by plugin so that a code generated for one purpose can never validate another one -
getEmailSubjectKey
-