Class PasswordResetService
Resets a forgotten password by mail.
@Bean
PasswordResetService passwordReset(OneTimeTokenService tokens, MailSender mail,
JdbcUserDetailsManager users, PasswordEncoder encoder) {
return new PasswordResetService(tokens, mail, users, users, encoder);
}
request(String, String) mails a link that works once and for half an hour; reset(String, String)
takes the token from that link and the new password. http.passwordReset()
puts both behind pages; an application with pages of its own calls the two
methods from its controllers.
request(String, String) returns the same way whether or not there is such a user, and
whether or not the mail could be sent, so that asking tells nobody which
accounts exist. The mail is handed to the server's mail queue, so the call
never waits for a mail server. For an account that exists it still makes a
token and stores it, which somebody timing many requests could measure:
limit how often it can be called. The pages do, a controller of the
application's own has to.
A reset removes the user's remember-me sign-ins when the service is given their store. A session that is already signed in stays so until it ends.
The mail is plain by default. Name a template to send the application's
own: it is rendered with link, username and minutes.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPasswordResetService(OneTimeTokenService tokens, MailSender mail, UserDetailsService users, UserDetailsPasswordService passwords, PasswordEncoder encoder) -
Method Summary
Modifier and TypeMethodDescriptionaddressResolver(EmailAddressResolver addressResolver) Where each user's mail goes.intThe shortest passwordreset(String, String)takes.booleanisAcceptable(String password) Whetherpasswordis onereset(String, String)would take.minimumLength(int minimumLength) The shortest passwordreset(String, String)takes; 8 unless set.rememberMeTokens(PersistentTokenRepository repository) The remember-me sign-ins to remove when a password is reset.voidMailsusernamea link toresetUrlwith atokenparameter added.booleanSets the password of the usertokenwas mailed to.The subject of the mail.The template the mail is rendered from, such asmail/password-reset, in place of the plain mail.validityMinutes(int validityMinutes) How long a link works; 30 minutes unless set.
-
Field Details
-
PURPOSE
-
-
Constructor Details
-
PasswordResetService
public PasswordResetService(OneTimeTokenService tokens, MailSender mail, UserDetailsService users, UserDetailsPasswordService passwords, PasswordEncoder encoder)
-
-
Method Details
-
addressResolver
Where each user's mail goes. Without one, a user name that is an address is used and other users are sent nothing. -
rememberMeTokens
The remember-me sign-ins to remove when a password is reset. -
validityMinutes
How long a link works; 30 minutes unless set. -
minimumLength
The shortest passwordreset(String, String)takes; 8 unless set. -
subject
The subject of the mail. -
template
The template the mail is rendered from, such asmail/password-reset, in place of the plain mail. -
getMinimumLength
public int getMinimumLength()The shortest passwordreset(String, String)takes. -
request
Mails
usernamea link toresetUrlwith atokenparameter added. Does nothing, and says nothing, when there is no such user, the account is disabled or it has no address.Parameters
username: the account, as the person asking typed itresetUrl: the whole address of the page that takes the new password,https://example.com/reset-password. Build it from the server's configured address, never from the request'sHostheader: that header is the caller's to choose, and the link is mailed to somebody else.
-
isAcceptable
Whetherpasswordis onereset(String, String)would take. -
reset
Sets the password of the usertokenwas mailed to. False when the token is not good -- wrong, expired or used -- or the password is too short. A password that is too short leaves the token good for another try. A token is used up before the password is stored, so that it cannot set two: if the store then fails, this throws what the store threw and the user asks for another link.
-