Interface EmailChangeOtpPlugin
- All Superinterfaces:
io.meeds.web.security.plugin.OtpPlugin
public interface EmailChangeOtpPlugin
extends io.meeds.web.security.plugin.OtpPlugin
The OTP method of the email change: the code goes to the new address, and
it confirms a change to that address only. It is stored bound to the
address it was sent to (
bindCode(String, String)), so the flow
validates and consumes it through OtpService
with the bound value of the code typed and of the address being set, never
with the code alone. A change also needs a code of the email
method, sent to the address of the account, and the former address is told
once the change is written.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceThe check of the new address, run under the send lock -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringThe value a code of this method is stored, validated and consumed as: the code and the address, lower-cased and trimmed.<R> RgenerateOtpCode(String userName, String newEmail, EmailChangeOtpPlugin.AddressCheck<R> addressCheck) Takes the send lock of the user first, then runs the check of the address, then sends a new code to the address when the check accepts it.voidsendChangeNotice(String userName, String formerEmail) Tells the former address of the user that the email of their account changed, without naming the new one, so that a change the owner of the account did not make is noticed where they still read their mail.Methods inherited from interface io.meeds.web.security.plugin.OtpPlugin
canUse, consumeOtp, generateOtpCode, getCodeTtlMinutes, getName, getSendIntervalSeconds, validateOtp
-
Field Details
-
NAME
- See Also:
-
-
Method Details
-
generateOtpCode
<R> R generateOtpCode(String userName, String newEmail, EmailChangeOtpPlugin.AddressCheck<R> addressCheck) throws Exception Takes the send lock of the user first, then runs the check of the address, then sends a new code to the address when the check accepts it. The lock holds for the send interval whatever the check answers, so a refused address is rate-limited like a send, and a request made while the lock holds is refused before the address is checked.- Type Parameters:
- Parameters:
userName- the user changing their emailnewEmail- the address to setaddressCheck- answers the refusal of the address, or null to send- Returns:
- the check's refusal, or null when the code was sent
- Throws:
IllegalStateException- when the lock is already held: nothing is checked or sentException- when the check fails
-
sendChangeNotice
Tells the former address of the user that the email of their account changed, without naming the new one, so that a change the owner of the account did not make is noticed where they still read their mail. Best effort: a failure to send is logged, never thrown.- Parameters:
userName- the user whose email changedformerEmail- the address of the account before the change
-
bindCode
The value a code of this method is stored, validated and consumed as: the code and the address, lower-cased and trimmed. A generated code holds digits only, so a typed code that holds anything else binds to nothing and the value is unambiguous: a code sent to one address never confirms another.- Parameters:
otpCode- the code, as sent or as typedemail- the address it was sent to, or the address being set- Returns:
- the bound value, null when the code or the address is blank or the code is not made of digits
-