Class AccountServices

java.lang.Object
com.jk.webstack.services.account.AccountServices
All Implemented Interfaces:
org.springframework.security.core.userdetails.UserDetailsService

public class AccountServices extends Object implements org.springframework.security.core.userdetails.UserDetailsService
This class provides user account-related services in a web application.

It implements the UserDetailsService interface for user authentication and retrieval.

Version:
1.0
Author:
Dr. Jalal H. Kiswani
  • Constructor Details

    • AccountServices

      public AccountServices()
      This method constructs a new AccountServices.
  • Method Details

    • loadUserByUsername

      public Account loadUserByUsername(String username) throws org.springframework.security.core.userdetails.UsernameNotFoundException
      Locates the user based on the user name.
      Specified by:
      loadUserByUsername in interface org.springframework.security.core.userdetails.UserDetailsService
      Parameters:
      username - the user name identifying the user whose data is required.
      Returns:
      a fully populated user record (never null)
      Throws:
      org.springframework.security.core.userdetails.UsernameNotFoundException - if the user could not be found or the user has no GrantedAuthority
    • createAccount

      public Account createAccount(String email, String firstname, String lastname, String password) throws AccountAlreadyExistsException
      This method create a new user account with the provided details.
      Parameters:
      email - Specifies the email address for the new account.
      firstname - Specifies the first name for the new account.
      lastname - Specifies the last name for the new account.
      password - Specifies the password for the new account.
      Returns:
      the created Account object.
      Throws:
      AccountAlreadyExistsException - if an account with the same email already exists.
    • processNewAccount

      protected void processNewAccount(Account account)
      This method process the creation of a new user account.
      Parameters:
      account - Specifies the Account object representing the new user account to be created.
    • processCurrentAccount

      protected void processCurrentAccount(Account account)
      This method process an existing user account.
      Parameters:
      account - Specifies the Account object representing the existing user account to be processed.
    • resetAccount

      public Account resetAccount(String email)
      This method reset the user account associated with the given email address.
      Parameters:
      email - Specifies the email address of the user account to reset.
      Returns:
      the updated Account object after resetting the account.
    • resetAccount

      protected void resetAccount(Account account)
      This method resets the provided user account's password and create a new token for it.
      Parameters:
      account - Specifies the user account to reset.
    • createLoginLink

      protected String createLoginLink(Account account)
      This method create a login link for the specified user account.
      Parameters:
      account - Specifies the user account for which the login link is created.
      Returns:
      a URL that can be used for user login with a token.
    • loadDetailsByToken

      public Account loadDetailsByToken(String tokenString)
      This method load user account details based on a token string.
      Parameters:
      tokenString - Specifies the token string used for authentication.
      Returns:
      the user account associated with the provided token.
    • resetToken

      protected void resetToken(Account account)
      This method reset the one-time token for a user account.
      Parameters:
      account - Specifies the user account for which the token needs to be reset.
    • createToken

      protected void createToken(Account account)
      This method create a one-time token for a user account.
      Parameters:
      account - Specifies the user account for which the token needs to be created.
    • main

      public static void main(String[] args)
      This main method demonstrate how to make a new account services object.
      Parameters:
      args - the command-line arguments.
    • setEmailVerified

      public void setEmailVerified(Account account)
      This method set the email verification status for a user account.
      Parameters:
      account - Specifies the user account for which the email verification status should be set.
    • findAccountByEmail

      protected Account findAccountByEmail(String email)
      This method find a user account by its email address.
      Parameters:
      email - Specifies the email address of the user account to find.
      Returns:
      the user account with the specified email address.
    • changePassword

      public void changePassword(String userName, String currentPassword, String newPassword)
      This method changes the password for a user account.
      Parameters:
      userName - Specifies the user name (email address) for the account.
      currentPassword - Specifies the current password.
      newPassword - Specifies the new password.