Class LoginService

java.lang.Object
hu.rts.mike.example.dev.crm.service.LoginService

@Service public class LoginService extends Object
  • Field Details

    • FORGOTTEN_PASSWORD_MAIL_TEMPLATE_PATH

      public static final String FORGOTTEN_PASSWORD_MAIL_TEMPLATE_PATH
      See Also:
    • CODE_LENGTH

      public static final int CODE_LENGTH
      See Also:
    • CODE_KEY

      public static final String CODE_KEY
      See Also:
    • passwordResetTokenExpiration

      @Value("${app.security.password-reset-token-expiration}") protected long passwordResetTokenExpiration
    • from

      @Value("${mail.from}") protected String 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

      private final AuthInfoRepository authInfoRepository
    • passwordChangeRepository

      private final PasswordChangeRepository 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:
      URISyntaxException
      jakarta.mail.MessagingException
    • storeCode

      public String storeCode(UUID uuid)
      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

      public void updatePassword(String code, String password)
      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

      public Optional<String> getMailTemplate(Locale locale)
      Loads the mail template.
      Parameters:
      locale - The locale of the template.
      Returns:
      The mail template.
    • generateCode

      protected static String generateCode()
      Generates a long random code that substitutes user id during the password change process.
      Returns:
      The generated code.
    • getCodeFromUrl

      public Optional<String> getCodeFromUrl(URL url) throws URISyntaxException
      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 code
      to - 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

      public boolean isStrong(String password)
      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

      public void setPassword(UserListDto userListDto, String password)
      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

      public void setPassword(AuthInfo authInfo, String password)
      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()