Class LoginService
java.lang.Object
hu.rts.mike.example.dev.crm.service.LoginService
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AuthInfoRepositorystatic final Stringstatic final intstatic final Stringprotected Stringprivate final org.springframework.mail.javamail.JavaMailSenderprivate final org.modelmapper.ModelMapperprivate final PasswordChangeRepositoryprivate final org.springframework.security.crypto.password.PasswordEncoderprotected intprotected booleanprotected booleanprotected booleanprotected longprivate final org.springframework.core.io.ResourceLoader -
Constructor Summary
ConstructorsConstructorDescriptionLoginService(AuthInfoRepository authInfoRepository, PasswordChangeRepository passwordChangeRepository, org.springframework.mail.javamail.JavaMailSender javaMailSender, org.springframework.security.crypto.password.PasswordEncoder passwordEncoder, org.springframework.core.io.ResourceLoader resourceLoader, org.modelmapper.ModelMapper mapper) -
Method Summary
Modifier and TypeMethodDescriptionprotected static StringGenerates a long random code that substitutes user id during the password change process.getCodeFromUrl(URL url) Extracts the unique password change code from the passed URL.getMailTemplate(Locale locale) Loads the mail template.intvoidinitiatePasswordChange(String userNameOrEmail, URL currentUrl, String path, String subject, String mailTemplate, String signature) Creates a code for the user that temporarily substitutes her current password.booleanbooleanbooleanbooleanIs the given password strong enough?voidsendMessage(String link, String to, String subject, String userDisplayName, String template, String signature) Sends an email for the user with a link to password change page.voidsetPassword(AuthInfo authInfo, String password) Encode the new plain text password and set it in the authInfo object.voidsetPassword(UserListDto userListDto, String password) Encode the new plain text password and set it in the authInfoDto object.Stores a userid - code - creation time triplet for later password changes.voidupdatePassword(String code, String password) Changes the password of the user identified by code.
-
Field Details
-
FORGOTTEN_PASSWORD_MAIL_TEMPLATE_PATH
- See Also:
-
CODE_LENGTH
public static final int CODE_LENGTH- See Also:
-
CODE_KEY
- See Also:
-
passwordResetTokenExpiration
@Value("${app.security.password-reset-token-expiration}") protected long passwordResetTokenExpiration -
from
-
passwordMinLength
@Value("${password.minlength}") protected int passwordMinLength -
passwordMustContainUppercaseLetter
@Value("${password.upper}") protected boolean passwordMustContainUppercaseLetter -
passwordMustContainLowercaseLetter
@Value("${password.lower}") protected boolean passwordMustContainLowercaseLetter -
passwordMustContainDigit
@Value("${password.digit}") protected boolean passwordMustContainDigit -
authInfoRepository
-
passwordChangeRepository
-
javaMailSender
private final org.springframework.mail.javamail.JavaMailSender javaMailSender -
passwordEncoder
private final org.springframework.security.crypto.password.PasswordEncoder passwordEncoder -
resourceLoader
private final org.springframework.core.io.ResourceLoader resourceLoader -
mapper
private final org.modelmapper.ModelMapper mapper
-
-
Constructor Details
-
LoginService
public LoginService(AuthInfoRepository authInfoRepository, PasswordChangeRepository passwordChangeRepository, org.springframework.mail.javamail.JavaMailSender javaMailSender, org.springframework.security.crypto.password.PasswordEncoder passwordEncoder, org.springframework.core.io.ResourceLoader resourceLoader, org.modelmapper.ModelMapper mapper)
-
-
Method Details
-
initiatePasswordChange
public void initiatePasswordChange(String userNameOrEmail, URL currentUrl, String path, String subject, String mailTemplate, String signature) throws URISyntaxException, jakarta.mail.MessagingException Creates a code for the user that temporarily substitutes her current password. She is going to get a mail to her e-mail address that redirects her to a page where she can enter the new password.- Parameters:
userNameOrEmail- Username or e-mail address of the user.currentUrl- The URL of the page that initiates the password change process.path- The path string of the page where the new password can be entered.subject- The subject of the mail.mailTemplate- The template of the mail body.signature- The signature to be appended to the end of the message.- Throws:
URISyntaxExceptionjakarta.mail.MessagingException
-
storeCode
Stores a userid - code - creation time triplet for later password changes.- Parameters:
uuid- The user's UUID- Returns:
- code The associated code (URL query parameter identifying the password change request)
-
updatePassword
Changes the password of the user identified by code.- Parameters:
code- The code identifying the password change request.password- The new, plain text password to be saved for the user.
-
getMailTemplate
Loads the mail template.- Parameters:
locale- The locale of the template.- Returns:
- The mail template.
-
generateCode
Generates a long random code that substitutes user id during the password change process.- Returns:
- The generated code.
-
getCodeFromUrl
Extracts the unique password change code from the passed URL.- Parameters:
url- The URL to be analysed.- Returns:
- The code.
- Throws:
URISyntaxException- If the syntax of the passed URL is incorrect.
-
sendMessage
public void sendMessage(String link, String to, String subject, String userDisplayName, String template, String signature) throws jakarta.mail.MessagingException Sends an email for the user with a link to password change page.- Parameters:
link- Link to the password change page including the unique codeto- Mail address of the user.subject- Subject of the message.userDisplayName- The user's real name.template- The mail template.signature- The signature at the end of the mail.- Throws:
jakarta.mail.MessagingException- If the mail cannot be sent.
-
isStrong
Is the given password strong enough? Checking for length and contained character types.- Parameters:
password- The password to be checked in plain text format.- Returns:
- True if the password is strong enough.
-
setPassword
Encode the new plain text password and set it in the authInfoDto object.- Parameters:
userListDto- The user information.password- The new plain text password to be set.
-
setPassword
Encode the new plain text password and set it in the authInfo object.- Parameters:
authInfo- The user information.password- The new plain text password to be set.
-
getPasswordMinLength
public int getPasswordMinLength() -
isPasswordMustContainUppercaseLetter
public boolean isPasswordMustContainUppercaseLetter() -
isPasswordMustContainLowercaseLetter
public boolean isPasswordMustContainLowercaseLetter() -
isPasswordMustContainDigit
public boolean isPasswordMustContainDigit()
-